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!

1
  • 3
    Do not make a variable name (str) that is the same as a data type (str). It's a bad thing to do. Commented Dec 11, 2009 at 11:23

2 Answers 2

7

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

Sign up to request clarification or add additional context in comments.

1 Comment

Python never fails to amaze me
0
try:
    i = int(sys.argv[1], 16)
except Exception,e:
    print e
else:
    # carry on

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.