Python:cmd传参

假如你写了一个文件test.py,你需要三个参数,你运行时:

python test.py arg1 arg2 arg3

在test.py中读取这几个参数:

import sys
 
print 'Number of arguments:', len(sys.argv), 'arguments.'
print 'Argument List:', str(sys.argv)

这样会给出输出:

Number of arguments: 4 arguments.
Argument List: ['test.py', 'arg1', 'arg2', 'arg3']
原文地址:https://www.cnblogs.com/jiu0821/p/6491049.html