[TIP] Teaching pylint about keyword placeholders in string formatting
marius at gedmin.as
Wed Jul 15 04:44:31 PDT 2009
On Wed, Jul 15, 2009 at 08:08:13PM +1000, Ben Finney wrote:
> Howdy all,
> A common idiom I use is::
> def frobnicate(warble):
> foo = complex_computation()
> bar = long.access.path.leading.to.useful.value
> baz = (lengthy + expression * with_several_parts)
> spangulate("%(warble)s: %(foo)s%(bar)s [%(baz)d]" % vars())
> This allows the format of the string to be clear, and allows the
> separate parts of it to have meaningful names.
> However, this is causing pylint to complain::
For some reason I mislike the use of vars()/locals()/globals() for use
cases other than debugging, so I tend to write
spangulate("%(warble)s: %(foo)s%(bar)s [%(baz)d]"
% dict(warble=warble, foo=foo, bar=bar, baz=baz))
and therefore never have the problem with pylint. (Though I prefer
pyflakes. Fewer erroneous warnings, or at least I got that impression.)
Strangely enough, playing with sys._getframe(1).f_globals is okay in my
book, if I really need it.
If the code and the comments disagree, then both are probably wrong.
-- Norm Schryer
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 189 bytes
Desc: Digital signature
Url : http://lists.idyll.org/pipermail/testing-in-python/attachments/20090715/17b1a904/attachment.pgp
More information about the testing-in-python