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

M.-A. Lemburg mal at egenix.com
Thu Oct 1 11:37:26 CEST 2009


Eric Smith wrote:
> Martin v. Löwis wrote:
>> Steven Bethard wrote:
>>> There's a lot of code already out there (in the standard library and
>>> other places) that uses %-style formatting, when in Python 3.0 we
>>> should be encouraging {}-style formatting. 
>>
>> I don't agree that we should do that. I see nothing wrong with using
>> % substitution.

I agree with Martin.

Both approaches have their ups and downs, but forcing users to move
from %-formatting to .format()-formatting will just frustrate them:
having to convert several thousand such (working) uses in their code
with absolutely no benefit simply doesn't look like a good way to
spend your time.

In addition to the code changes, such a move would also render
existing translations of the %-formatted string templates useless.

> It's a maintenance burden. There are several outstanding bugs with it,
> admittedly not of any great significance. I've been putting time into
> fixing at least one of them. When Mark and I did short-float-repr, at
> least half of my time was consumed with %-formatting, mostly because of
> how it does memory management.

Why not allow both and use .format() for those cases where %-formatting
doesn't work too well ?

> On the plus side, %-formatting is (and always will be) faster than
> str.format(). Its very limitations make it possible for it to be fast.
> 
> I'd note that PEP 3101 calls str.format() a replacement for
> %-formatting, not an alternate mechanism to achieve the same end.

I think that's a wording we should change.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Oct 01 2009)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________

::: Try our new mxODBC.Connect Python Database Interface for free ! ::::


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               http://www.egenix.com/company/contact/


More information about the Python-Dev mailing list