3

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!

SilentGhost
  • 307,395
  • 66
  • 306
  • 293
bbb
  • 267
  • 1
  • 3
  • 6
  • 3
    Do not make a variable name (`str`) that is the same as a data type (`str`). It's a bad thing to do. – S.Lott Dec 11 '09 at 11:23

2 Answers2

7

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

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
0
try:
    i = int(sys.argv[1], 16)
except Exception,e:
    print e
else:
    # carry on
ghostdog74
  • 327,991
  • 56
  • 259
  • 343