4

I want the user to provide some external arguments while calling a python script from command line, what changes I suppose to make inside my python script to add this functionality?

3
  • Maybe you should show your python script that is in question? Commented Sep 30, 2016 at 5:16
  • 1
    Did you do some preliminary research first? Go through this doc, perhaps it'll help. docs.python.org/3/library/argparse.html Commented Sep 30, 2016 at 5:17
  • Either use sys.argv or argparse Commented Sep 30, 2016 at 5:34

1 Answer 1

3

I think this is what you are looking for

pass arguments in command line.

$ python test.py arg1 arg2 arg3

access it using sys.argv which gives list of arguments that you entered above

import sys

print 'Number of arguments:', len(sys.argv), 'arguments.'
print 'Argument List:', str(sys.argv)
Sign up to request clarification or add additional context in comments.

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.