[Python-3000] PEP 3101 str.format() equivalent of '%#o/x/X'?
Nick Coghlan
ncoghlan at gmail.com
Thu May 29 11:47:37 CEST 2008
wesley chun wrote:
> i have to resort to the uglier:
>
>>>> 'dec: {0}/oct: 0o{0:o}/hex: 0X{0:X}'.format(i)
> 'dec: 45/oct: 0o55/hex: 0X2D'
Is being explicit about the displayed prefix really that much uglier?
The old # alternative display formats were somewhat arbitrary.
> is this functionality being dropped, or am i missing something? i
> didn't get anything from searching the Py3000 mailing list archives. i
> couldn't find anything in either formatter.h nor stringobject.c.
>
> secondly, and much more minor, is that i think there's a minor typo in the PEP:
> print format(10.0, "7.3g") <-- print() is now a function so it needs
> another pair of ( ).
It works fine as written in 2.x :)
(but, yes, you're right that as a 3000-series PEP, 3101 should probably
treat print() as a function in its examples)
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
More information about the Python-3000
mailing list