[Python-Dev] transitioning from % to {} formatting

Guido van Rossum guido at python.org
Thu Oct 8 18:55:11 CEST 2009

On Thu, Oct 8, 2009 at 8:08 AM, Christian Tanzer <tanzer at swing.co.at> wrote:
> All that talk of deprecating %-formatting makes me really nervous.
> %-formatting is pervasive in all existing Python code.
> Without an automatic translator that is 100% accurate, porting all
> that code to {}-formatting is not possible. Heck, it's not even
> possible to grep for all instances of %-formatting.
> How do you suppose that maintainers could ever do the transition from
> %- to {}-formatting manually?

This is pretty much the situation with integer division (you can only
recognize it by running the code), and yet we figured a way to change
that in 3.x. Or take classic classes vs. new-style classes. They
cannot be translated 100% automatically either. The solution is to
support the old and new style in parallel for a really long time -- we
did this with int division (read PEP 238), we did it with classes, and
we can do it again with formatting.

Unless I missed something, we're not planning to remove %-formatting
until Python 4.0 comes along, which we won't even start until a long
time after everyone has switched to some version of 3.x. So the same
approach will apply: support both forms, nudge people to start using
the new form, wait, nudge some more, etc.

So, yes, we will continue to make noise about this. And yes you should
opportunistically migrate your code to {}-formatting, like when you're
rewriting some code anyway. One of the nice things about {}-formatting
is that in most cases (things like the logging API excluded) you can
change it one format string at a time.

And no, the sky isn't falling.

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

More information about the Python-Dev mailing list