[ home | blog home | recent activity ]
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.
Comments:
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.Post a new comment:
Three things:
If you can't for some reason post a comment, send me an email: willg at bluesock dot org.
pyblosxom::1.5-dev git-master
Copyright 1996 to 2012, Will Guaraldi Kahn-Greene, under the Creative Commons BY-SA 3.0 license

Will's Blog by William Kahn-Greene is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.