sys.argv[0] is the name of the file being executed
suggest changesys.argv[0] is the name of the Python file being executed. The remaining elements of sys.argv are the script arguments.
# script.py
import sys
print(sys.argv[0])
print(sys.argv)
$ python script.py
=> script.py
=> ['script.py']
$ python script.py fizz
=> script.py
=> ['script.py', 'fizz']
$ python script.py fizz buzz
=> script.py
=> ['script.py', 'fizz', 'buzz']
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents