[Python-ideas] String formatting and namedtuple

Guido van Rossum guido at python.org
Mon Feb 16 17:04:48 CET 2009

On Mon, Feb 16, 2009 at 12:48 AM, Christian Tanzer <tanzer at swing.co.at> wrote:
> A fair amount of my use cases involve a non-literal format string
> (i.e., passed in as argument, defined as module or class variable, or
> even doc-strings used as format strings). I'd guess that most
> non-literal format strings are used together with dictionaries.
> Unfortunately, it's hard to grep for this :-(, so I can't give you
> hard numbers.

It would be pretty simple to rig up 2to3 to report any string literals
containing e.g. '%(...)s' that are not immediately followed by a %

> Another, probably fairly common, use case involving non-literal
> strings is %-formatting in I18N strings -- though it might be possible
> to fix these automatically.

Plus, i18n is one of the motivators for .format() -- less chance of
forgetting to type the trailing 's' in '%(foobar)s' and the ability to
rearrange positional arguments a la "foo {1} bar {0} baz".

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-ideas mailing list