I would like to convert either 0x123, 012 or 36#foo into an integer.
To do so, I wrote this:
def str2int(s):
if re.findall('(?i)^0x',s):
return int(s, 16)
if re.findall('^(?i)0',s):
return int(s, 8)
m = re.findall('(?i)^(\d+)\#([0-9a-z]+)',s)
if m:
return int(m[0][1], m[0][0])
raise AssertionError, 'Unknown value'
I feel it is a bit complicated. Is there any builtin method?
base#numberis not a built-in supported expression format.