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

Nick Coghlan ncoghlan at gmail.com
Sat Oct 3 11:37:00 CEST 2009

Bugbee, Larry wrote:
> So until I see a *significant* benefit, my vote is *not* remove
> %-formatting.  Make both available and if {} is to win, it will.

Percent formatting isn't going anywhere (certainly not for the next
decade or so). However, its well documented limitations (especially the
lack of extensibility) and error-prone syntax (handling of dicts and
tuples, forgetting trailing type codes in namespace formatting, operator
precedence issues) are what led directly to PEP 3101 and the
introduction of brace formatting.

For the basic cases that percent formatting actually covers, it does a
reasonable job and is often more concise and currently executes faster
than the brace formatted equivalent (this was especially the case before
support for implicit positional argument numbering was added to brace

The advantages of brace formatting don't really start to show up until
you actually start using the *new* features that the approach provides,
such as formatting for non-builtin types (e.g. Decimal and datetime
objects), referring to argument subscripts and attributes in field
definitions and the optional explicit numbering of references to
positional arguments (allowing the order of interpolation to be changed
in the format string without having to change the argument order in all
uses of that format string).

Also, don't forget that the percent formatting code has been around for
more than a decade and a half and has been optimised over that time. The
brace formatting code, on the other hand, is relatively new and probably
still offers plenty of opportunities for optimisation (although the
additionally flexibility in the brace formatting approach means that it
is unlikely to ever catch up completely to the raw speed of percent


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-Dev mailing list