int() should be extended?

Xiao-Qin Xia xx758 at cam.ac.uk
Mon Oct 21 11:42:34 EDT 2002


Hi, there,

int() can convert some string into integer, except a string from hex():
"""
>>> int("41")
41
>>> int("041")
41
>>> int("0x41")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: invalid literal for int(): 0x41
>>>
>>> exec "c = 0x41"
>>> c
65
"""

since use exec is not so good a habit, is there any other way to convert 
"0x41" to 65 (0x41)?, or int() should be extened to do this job?

Thanks, 
Xiao-Qin Xia



More information about the Python-list mailing list