例如 - 我想做点什么......
python DoublePendulum.py INPUT1 INPUT2
(其中INPUT1和INPUT2作为DoublePendulum程序中的变量输入).
$ python test.py arg1 arg2 arg3
Run Code Online (Sandbox Code Playgroud)
在test.py中
import sys
print 'Number of arguments:', len(sys.argv), 'arguments.'
print 'Argument List:', str(sys.argv)
Run Code Online (Sandbox Code Playgroud)
产量
Number of arguments: 4 arguments.
Argument List: ['test.py', 'arg1', 'arg2', 'arg3']
Run Code Online (Sandbox Code Playgroud)
Python还提供了可帮助您解析命令行选项和参数的模块.标准库中有以下模块: