Python provides a getopt module that helps you parse command-line options and arguments.

$ python test.py arg1 arg2 arg3 The Python sys module provides access to any command-line arguments via the sys.argv. This serves two purposes −

sys.argv is the list of command-line arguments. len(sys.argv) is the number of command-line arguments. Here sys.argv[0] is the program ie. the script name.

Link to the original article