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

Vinay Sajip vinay_sajip at yahoo.co.uk
Sun Oct 4 00:43:18 CEST 2009

Brett Cannon <brett <at> python.org> writes:

> No one is saying we should deprecate % any time soon on strings
> themselves or anywhere. This discussion is purely in regards to
> argparse and logging to transition *their* APIs over to {} formatting
> which would most likely involve some deprecation for *using* %
> formatting in those APIs. But % formatting on strings themselves is
> not directly being discussed here.

While I have no problem with supporting {}-formatting in logging if we find a
good way of doing it, one thing that bothers me about transitioning the logging
API to deprecate or otherwise de-emphasise %-formatting is the question of
performance. Now, str.format is more flexible than str.__mod__ and so some
performance loss may be tolerable in many scenarios. However, in the feedback I
regularly get about logging, people are concerned about performance. No-one ever
comes up with any hard numbers, but logging is often bashed as slow (see e.g.
Andrii Mishkovskyi's LoggingPackage page on the Python wiki). I don't especially
want to add fuel to the fire, as any performance degradation caused by
supporting {}-formatting will likely just result in more finger-pointing at
logging in general.


Vinay Sajip

More information about the Python-Dev mailing list