How to convert string to hex integer in Python?

hi I get user argv from the command line as follows: '0x000aff00'

and I want python to treat it as hex directly ...

str = sys.argv[1]

how is this possible? thanks!

+3
source share
2 answers

Try: i = int(sys.argv[1], 16)

+7
source
try:
    i = int(sys.argv[1], 16)
except Exception,e:
    print e
else:
    # carry on
0
source

Source: https://habr.com/ru/post/1725387/


All Articles