In Miro, we've got long strings that are displayed in the user interface. I think the code that defines these strings is messy and hard to parse. For example:
def some_func():
description = _("""\
This is a really long description that has multiple sentences and a few \
things that need to %(getfilledin)s and it goes on and on and on and on \
and I'm not really sure what's the best way to format it so that it's happy \
in editors and easier to parse.""") % {"getfilledin": blahblah}
PEP-8 doesn't address this, which is fine. I was curious to see what other projects do.
def some_func():
description = _(
"This is a really long description that has multiple sentences and a few "
"things that need to %(getfilledin)s and it goes on and on and on and on "
"and I'm not really sure what's the best way to format it so that it's happy "
"in editors and easier to parse.") % {"getfilledin": blahblah}
Feel free to edit this before publication: I don't know the pyblosxom markup conventions.
def some_func():
description = _(
"This is a really long description that has multiple sentences and a few "
"things that need to %(getfilledin)s and it goes on and on and on and on "
"and I'm not really sure what's the best way to format it so that it's happy "
"in editors and easier to parse."
) % {"getfilledin": blahblah}
from textwrap import dedent
def function():
x = dedent("""
Start here.
Indented.
Coz it looks better.
"""[1:] % values)
Notice the [1:] to trim the leading LF and the dedent function so that you can indent your long strings inline with whatever is using them.Please keep comments appropriate. I reserve the right to remove anonymous comments, flames, spammy, inappropriate, and other comments that I deem to be worth removing.
Note: New comments get placed in a "draft" status and will NOT show up on the site until I explicitly approve it. Usually that happens within 24 hours, but sometimes I go away and it takes a day or two.
Note 2: There is now a preview button for those of you who want to see a preview! However, it doesn't quite work the way you'd think it should work. I'll look into adjusting it some day.
Note 3: If you can't for some reason post a comment, send me an email: willg at bluesock dot org.
All contents Copyright 1996 to 2008 Will Guaraldi.
This work is licensed under a
Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.