Passing arguments when running with python code example
Example 1: program arguments python
#!/usr/bin/python
import sys
for args in sys.argv:
print(args)
"""
If you were to call the program with subsequent arguments, the output
will be of the following
Call:
python3 sys.py homie no
Output:
sys.py
homie
no
"""
Example 2: how to pass parameters in python script
#!/usr/bin/python
import sys
print 'Number of arguments:', len(sys.argv), 'arguments.'
print 'Argument List:', str(sys.argv)
# python scriptName.py arg1 arg2 arg3
# Output:
# Number of arguments: 4 arguments.
# Argument List: ['test.py', 'arg1', 'arg2', 'arg3']