Your solution:
def parseint(val):
if isinstance(val, int):
return val
if not isinstance(val, (unicode,str)):
return None
try:
if val.startswith('0x'):
return int(val, 16)
if val.startswith('0'):
return int(val, 8)
return int(val)
except ValueError:
return None
No comments:
Post a Comment