When known to the interpreter, the script name and additional
arguments thereafter are passed to the script in the variable
sys.argv
, which is a list of strings. Its length is at least
one; when no script and no arguments are given, sys.argv[0]
is
an empty string. When the script name is given as '-'
(meaning
standard input), sys.argv[0]
is set to '-'
. When
-c command is used, sys.argv[0]
is set to
'-c'
. Options found after -c command are
not consumed by the Python interpreter's option processing but left in
sys.argv
for the command to handle.
调用解释器时,脚本名和附加参数之传入一个名为 sys.argv
的字符串列表。没有脚本和参数时,它至少也有一个元素:
sys.argv[0]
此时为空字符串。脚本名指定为 '-'
(表示标准输入)时, sys.argv[0]
被设置为'-'
,使用
-c 指令 时, sys.argv[0]
被设定为'-c'
。 -c 命令之后的参数不会被
Python 解释器的选项处理机制所截获,而是留在sys.argv
中,供脚本命令操作。