[ home | blog home | recent activity | guestbook | plugins i'm using (19) ]
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.I reserve the right to remove comments that are anonymous, flames, spammy, inappropriate and/or rude. Sometimes I'll reply in email directly--so make sure your email address is correct. New comments get placed in a "draft" status and will NOT show up on the site until I explicitly approve it. Sometimes that happens within 24 hours.
If you can't for some reason post a comment, send me an email: willg at bluesock dot org.
All contents Copyright 1996 to 2010 Will Guaraldi Kahn-Greene.
This work is licensed under a
Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.