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

Eric Smith eric at trueblade.com
Sat Oct 10 18:09:33 CEST 2009

Nick Coghlan wrote:
> 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).

Mark points out in http://bugs.python.org/issue7094 that we'd also need 
to add alternate float formatting for any automated translation facility 
to work flawlessly. There might be other float issues involving trailing 
decimals with no zeros that work differently, too.


More information about the Python-Dev mailing list