Windows在从shell中执行的Python程序中没有传递命令行参数。

13 浏览
0 Comments

Windows在从shell中执行的Python程序中没有传递命令行参数。

如果我尝试从Windows命令行直接执行Python程序作为可执行命令,我会遇到传递给Python程序的命令行参数的问题。例如,如果我有这个程序(test.py):

import sys
print "Args: %r" % sys.argv[1:]

并执行:

>test foo
Args: []

与下面的执行结果进行比较:

>python test.py foo
Args: ['foo']

我的配置如下:

PATH=...;C:\python25;...
PATHEXT=...;.PY;....
>assoc .py
.py=Python.File
>ftype | grep Python
Python.CompiledFile="C:\Python25\python.exe" "%1" %*
Python.File="C:\Python25\python.exe" "%1" %*
Python.NoConFile="C:\Python25\pythonw.exe" "%1" %*

0