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

Nick Coghlan ncoghlan at gmail.com
Sat Oct 10 18:05:27 CEST 2009


Benjamin Peterson wrote:
> 2009/10/8 Eric Smith <eric at trueblade.com>:
>> Christian Tanzer wrote:
>>> IMHO, either the translation is done once and gives identical output or
>>> it isn't worth doing at all.
>> I disagree. I doubt even 0.001% of all format strings involve octal
>> formatting. Is it really worth not providing a transition path if it can't
>> cover this case?
> 
> It's also really easy to just write 0{:o} like my translator does.

That works so long as the original format string doesn't specify either
a space padded field width or else a sign character. For those the extra
zero needs to be inserted after the leading characters but before the
number, so the formatting engine really has to handle it.

I'm actually thinking that having the ability to specify a single 0 as
the leading character for octal output is a legitimate feature. There
are plenty of other tools out there that use a single leading zero to
denote octal numbers (e.g. think of a Python script that generated C
code), so having Python be able to produce such numbers makes a lot of
sense.

Vinay's suggestion of using 'O' instead of 'o' to denote C-style octal
formatting instead of Python-style sounds reasonable to me (similar in
degree to the upper vs lower case distinction for 'x' and 'X' hex
formatting).

Cheers,
Nick.

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


More information about the Python-Dev mailing list