2

I'm learning python. So here's what I'm after:

Inside a python script I have the following:

back_minutes1 = int(sys.argv[2])
back_minutes = timedelta(minutes=back_minutes)

This works fine, but I'm essentially creating a 'trash variable' to make it work. If this were say bash, I could probably do something like

back_minutes = timedelta(minutes=`int(sys.argv[2])`)

This, of course doesn't work. What's the pythonic way to do this without creating this throw-away variable?

1 Answer 1

4

Why not

back_minutes = timedelta(minutes=int(sys.argv[2]))
Sign up to request clarification or add additional context in comments.

2 Comments

Oh good grief! I could have sworn I tried that. I can't believe it just worked. How embarrassing. I'll mark your answer as correct once it allows me. Thanks... :)
Not a problem, if your looking for proper command line arguments use argparse in python 2.7+

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.