int() built-in and hex "0x..." strings

Bruce Edge bedge at troikanetworks.com
Mon Jul 23 14:07:57 EDT 2001


I can't believe this doesn't work:

>>> int('0x80')                                                                                          
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: invalid literal for int(): 0x80

Do I really need to parse out the '0x' 1st, then based on it's
absence/presence do either:
int('80', 16)
or
int('80')
?

Is there another int() type lib func that I should use instead?

-thanks, Bruce.



More information about the Python-list mailing list