int() shortcoming?
Erik Max Francis
max at alcyone.com
Sat Nov 23 01:25:33 EST 2002
Matthew Knepley wrote:
> Is there a reason I should have to specify the base for a
> string
> conversion using int() when it is already clear from the form? For
> instance:
>
> >>> oct(15)
> '017'
> >>> int('017')
> 17
> >>> int('017', 8)
> 15
>
> and hexidecimal actually generates an error.
You can pass 0 in as the radix to int and it will automatically
determine the base. Clever, huh?
>>> int('017', 0)
15
>>> int('0x17', 0)
23
--
Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/ \ The little I know, I owe to my ignorance.
\__/ Sacha Guitry
Bosskey.net: Counter-Strike / http://www.bosskey.net/cs/
A personal guide to Counter-Strike.
More information about the Python-list
mailing list