[Python-3000] PEP 3101 str.format() equivalent of '%#o/x/X'?

Bruce Leban bruce at leapyear.org
Sat Jun 7 08:48:55 CEST 2008


It seems somewhat illogical to require [#][sign] in that order when the
parts inserted by them go in the opposite order.

So if a specific order is required, then I think it should be reversed.

'=' padding goes in the wrong order too: perhaps -#0=20d makes more sense
than 0=-#20d. I don't find that quite as compelling and I don't think it's
worth having everything go in any order just so that one can. (Then again, I
like the printf style -#020d.)

--- Bruce

On Fri, Jun 6, 2008 at 3:53 PM, Eric Smith
<eric+python-dev at trueblade.com<eric%2Bpython-dev at trueblade.com>>
wrote:

> Nick Coghlan wrote:
>
>> Doing the right thing for negative numbers is a good point. It also means
>> the prefix can be handled properly when dealing with aligned fields. The
>> following update to the standard format specifier in the PEP:
>>
>>  [[fill]align][#][sign][0][minimumwidth][.precision][type]
>>
>>  The '#' prefix option inserts the appropriate prefix characters ('0b',
>> '0o', '0x', '0X') when displaying numbers in binary, octal or hexadecimal
>> formats. The prefix is inserted into the displayed number after the sign
>> character and fill characters (if any), but before any leading zeroes.
>>
>
> I was implementing this today, and I note that %-formatting doesn't specify
> an order among the #, sign, and 0 flags (at least not that I could tell by
> experimentation).  PEP 3101 does say that sign comes before 0 for
> str.format().  Do we want the # to come before sign?  Do we want an order at
> all?
>
> This sort of surprised me when I was writing tests.  Even after having
> implemented it, I was expecting "-#x" to work, but it needs to be "#-x".
>
> I don't mind there being a fixed order (in fact I prefer it for a number of
> reasons), I just want to make sure that the order specified above is what we
> want to go with.
>
> Eric.
>
> _______________________________________________
> Python-3000 mailing list
> Python-3000 at python.org
> http://mail.python.org/mailman/listinfo/python-3000
> Unsubscribe:
> http://mail.python.org/mailman/options/python-3000/bruce%40leapyear.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-3000/attachments/20080606/850f2135/attachment-0001.htm>


More information about the Python-3000 mailing list