[Python-ideas] String formatting and namedtuple

Christian Tanzer tanzer at swing.co.at
Mon Feb 16 09:48:14 CET 2009

Guido van Rossum wrote at Fri, 13 Feb 2009 09:56:55 -0800:

> On Fri, Feb 13, 2009 at 12:58 AM, Christian Tanzer <tanzer at swing.co.at> wrote:
> > I think the main problem is the huge amount of existing code that uses
> > `%` for formatting. As long as there is no easy way to migrate that
> > code to `.format`, moves to deprecate `%`-formatting are bound to
> > cause friction.
> Yes, that was our concern too when we decided to keep % without
> deprecation in 3.0.
> My guess is that *most* of these use string literals, and we *can*
> write a 2to3 fixer for those.
> It is the cases where the format is being passed in as an argument or
> precomputed somehow where 2to3 falls down. It would be useful to have
> an idea how frequently that happens.

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.

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

Christian Tanzer                                    http://www.c-tanzer.at/

More information about the Python-ideas mailing list