[Python-3000] PEP 3101 str.format() equivalent of '%#o/x/X'?
wesley chun
wescpy at gmail.com
Sun Jun 1 01:41:38 CEST 2008
>>> I'd be fine with adding '#' back to the formatting language for hex and oct.
>>
>> And bin, I assume?
>
> Of course.
somewhat on-topic, can i hear from some of you as far as use-cases for
oct() and hex() [plus bin()] in Python code? i find "%x" or "%o" (and
its variants) sufficient in serving my needs. in other words, why
oct() and hex() built-in functions instead of elsewhere like in
operator for those who desire a functional interface?
another related inquiry, if we're going to have hex(), can its
signature be expanded to include "%#X" functionality, i.e.,
hex(number, cap=False), as the default and someone who wants the "#"
can do hex(123, cap=True)? on top of that, can hex() also support "%x"
and '%X' functionality, i.e., hex(number, cap=False, leading=True), as
the default, so i can do hex(123, leading=False) for '7b'? do you see
how i'm trying to make life difficult and lead people down the path of
not having hex(), oct(), or bin()? or are those three functions
intended to obsolete "#"? :-)
writing this message made me realize that i could have just done the
following in my original post that started this whole thread:
>>> i = 45
>>> 'dec: {0}/oct: {1}/hex: {2}'.format(i, oct(i), hex(i))
'dec: 45/oct: 0o55/hex: 0x2d'
it's definitely better than the "uglier" code in that post although
this is less elegant than being able to specify the variable 'i' just
once.
cheers,
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
http://corepython.com
wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
More information about the Python-3000
mailing list