Passing command line arguments to Python script

Posted on 18-01-2017 by Nadir Latif


Command line arguments can be passed to a Python script. For example the parameters passed to python script_name argument1 argument2 argument3 can be read with the sys module. The sys module provides the command line arguments. To use the sys module, we have to use the command: import sys. The command line arguments can be used as: sys.argv[0], sys.argv[1], sys.argv[2]. The number of command line arguments can be read with: len(sys.argv).