bbb
bbb

Reputation: 267

How to convert string to hexadecimal integer in Python?

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

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

str = sys.argv[1]

how is it possible? thanks!

Upvotes: 3

Views: 2980

Answers (2)

ghostdog74
ghostdog74

Reputation: 342273

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

Upvotes: 0

Aaron Digulla
Aaron Digulla

Reputation: 328536

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

Upvotes: 7

Related Questions