- sys
- argv
Command line arguments
examples/basics/cli.py
import sys def main(): print(sys.argv) print(sys.argv[0]) print(sys.argv[1]) print(sys.argv[2]) main()
$ python examples/basic/cli.py one two
['examples/basics/cli.py', 'one', 'two'] examples/basics/cli.py one two
$ python examples/basic/cli.py
['examples/basics/cli.py'] examples/basics/cli.py Traceback (most recent call last): File "examples/basics/cli.py", line 6, in <module> print(sys.argv[1]) IndexError: list index out of range