标签: python integer hex
嗨,我从命令行获取用户argv,如下所示:'0x000aff00'
'0x000aff00'
我希望python直接将其视为十六进制......
str = sys.argv[1]
怎么可能?谢谢!
答案 0 :(得分:7)
尝试:i = int(sys.argv[1], 16)
i = int(sys.argv[1], 16)
答案 1 :(得分:0)
try: i = int(sys.argv[1], 16) except Exception,e: print e else: # carry on