问题描述
我想我解决了这个问题。出于某种原因,注册表中存在第二个位置(除了存储在HKEY_CLASSES_ROOT \ Python.File \ shell \ open \ command中的文件关联所显示的位置):
[HKEY_CLASSES_ROOT\Applications\python.exe\shell\open\command] @="\"C:\\Python25\\python.exe\" \"%1\" %*"
@H_301_5@这似乎是我系统上的控制设置。上面的注册表设置添加了“%*”以将所有参数传递给python.exe(由于某种原因,它在我的注册表中丢失了)。
解决方法
如果尝试从Windows命令外壳将它们作为可执行命令直接执行,则无法将命令行参数传递给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" %*