hex oct int string coversions?

Ron Adam radam2 at tampabay.rr.com
Sun Nov 2 20:32:05 EST 2003



How do I covert a string hex or oct value to the correct int value?

>>> s = oct(500)
>>> s			# returns a oct string
'0764'

>>> int(0764)       	 # ok
500

>>> int(s)		# this gives the wrong value
764

>>> t = hex(500)
>>> t			# returns a hex string
'0x1f4'

>>> int(0x1f4)       	 # ok
500

>>> int(t)		# causes an error
Traceback (most recent call last):
  File "<pyshell#65>", line 1, in ?
    int(t)
ValueError: invalid literal for int(): 0x1f4








More information about the Python-list mailing list