int('0x0001')

Fredrik Lundh effbot at telia.com
Thu Mar 16 10:55:15 EST 2000


Michal Bozon wrote:
> Why int() cannot handle string of hexadecimal representation of integer?
> I mean e.g.  int('0xA') -> 10.

the documentation clearly says that 'int' only works
if the string contains a *decimal* number.

0xA is not a decimal number.

(and according to most people on earth, 0xA isn't a
number at all...).

> I have to use eval('0xA')

the docs for 'int' also mentions 'string.atoi', and if you
look that one up in the documentation, you'll find that
string.atoi(string, 0) does exactly what you want.

</F>





More information about the Python-list mailing list