Reading Time: 1 minutes
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.