[Python-3000] PEP - string.format

Nick Coghlan ncoghlan at gmail.com
Sat Apr 22 15:27:22 CEST 2006


Guido van Rossum wrote:
> On 4/22/06, Nick Coghlan <ncoghlan at gmail.com> wrote:
>>    Removing string %-formatting would be a backwards compatibility nightmare.
>> I doubt there's a Python program on the planet that would continue working if
>> it was removed (I know most of mine would break in verbose mode). Even those
>> which continued to work would likely break if all commented out debugging
>> messages were uncommented.
> 
> The same is true for some other changes considered, e.g. the new I/O
> stack, all-unicode strings, and dict views.
> 
> Py3k exists to *break* backwards compatibility. A format() method
> added to strings could be added to 2.6. Defining format() in terms of
> % would be a long-term disaster IMO.

That (adding .format() in 2.6) occurred to me, but I dismissed it for some 
reason. It can't have been a very good reason though, since I sure can't 
remember what it was.

In which case, Talin's PEP should probably suggest this as the implementation 
strategy - python3warn and the instrumented python build can do their best to 
pick up usage of % formatting, and we can add .format() to 2.6 so that forward 
compatible code can be written in later 2.x releases.

Now that I think about it, simply having python3warn pick up all uses of % in 
a print statement should pick up many of the uses of string formatting. (Not 
all, obviously, but a lot of them)

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-3000 mailing list