Python @ DjangoSpin

Python: Collecting arguments passed to a Python script

Buffer this pageShare on FacebookPrint this pageTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUpon
Reading Time: 1 minutes

Collecting arguments passed to a Python script

Collecting arguments passed to a Python script

The builtin sys module exposes objects used or maintained by the Python interpreter. One of these objects is argv, which is a list that captures the arguments passed to a Python script while calling it.

# anyPythonFile.py
import sys
print(sys.argv)

# From the command prompt
$ python path_to_anyPythonFile.py hello there !

# OUTPUT
['anyPythonFile.py', 'hello', 'there', '!']

Note that argv[0] is the name of file itself.


See also:

Buffer this pageShare on FacebookPrint this pageTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUpon

Leave a Reply