222 – Command line arguments

222 – Command line arguments#

The list sys.argv contains all the arguments your program was called with, including the program name. Suppose the file myscript simply prints the list:

import sys

print(sys.argv)

Here is an example invocation:

$ python myscript.py test --flag=2
['myscript.py', 'test', '--flag=2']

Note how there is no parsing involved. The elements of the list are the whitespace-separated arguments written in front of the program name.