[Python-3000] PEP 3101 str.format() equivalent of '%#o/x/X'?
Eric Smith
eric+python-dev at trueblade.com
Sat Jun 7 00:53:42 CEST 2008
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.
More information about the Python-3000
mailing list