Command Line Arguments

You can access arguments passed into a python script using the argv property of python’s sys object. You will need to import sys for this to work.

# args.py
import sys

for arg in sys.argv:
	print(arg)

Below is an example of the above script called with a list space separated inputs. The first argument at index 0 in the argv property will be the script that was called for python execution, followed by the arguments used.

$ python3 args.py 1 hello 3.2
> args.py
> 1
> hello
> 3.2