mck*_*oss 83 python windows registry file-association command-line-arguments
如果我尝试直接将它们作为可执行命令从Windows命令shell执行,那么我无法将命令行参数传递给Python程序.例如,如果我有这个程序(test.py):
import sys
print "Args: %r" % sys.argv[1:]
Run Code Online (Sandbox Code Playgroud)
并执行:
>test foo
Args: []
Run Code Online (Sandbox Code Playgroud)
相比于:
>python test.py foo
Args: ['foo']
Run Code Online (Sandbox Code Playgroud)
我的配置有:
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" %*
Run Code Online (Sandbox Code Playgroud)
mck*_*oss 99
我想我解决了这个问题.由于某种原因,注册表中存在第二个位置(除了存储在HKEY_CLASSES_ROOT\Python.File\shell\open\command中的文件关联所示):
[HKEY_CLASSES_ROOT\Applications\python.exe\shell\open\command]
@="\"C:\\Python25\\python.exe\" \"%1\" %*"
Run Code Online (Sandbox Code Playgroud)
这似乎是我系统的控制设置.上面的注册表设置添加"%*"以将所有参数传递给python.exe(由于某种原因,它在我的注册表中丢失).
对于Windows 7上的Python 3.3,我的设置是在另一个注册表项下; 我改变的关键是让参数得到通过
HKEY_USERS\S-1-5-21-3922133726-554333396-2662258059-1000_Classes\py_auto_file\shell\open\command
是的"C:\Python\Python33\python.exe" "%1".我只附加%*了它.钥匙的价值现在是"C:\Python\Python33\python.exe" "%1" %*.
我有几个(至少五个)其他键的值"C:\Python\Python33\python.exe" "%1",但这是我改变的那个使它工作.
为了让它为我工作,我必须使用注册表路径:
HKEY_CLASSES_ROOT\py_auto_file\shell\open\command
Run Code Online (Sandbox Code Playgroud)
并添加了一个%*
以下是针对 Python 3.6、2.7 和 Anaconda3 修复的 .reg 文件:
python-3.6.0.reg
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.py]
@="Python.File"
"Content Type"="text/plain"
[HKEY_CLASSES_ROOT\.pyc]
@="Python.CompiledFile"
"Content Type"="text/plain"
[HKEY_CLASSES_ROOT\.pyw]
@="Python.NoConFile"
"Content Type"="text/plain"
[HKEY_CLASSES_ROOT\py_auto_file]
[HKEY_CLASSES_ROOT\py_auto_file\DefaultIcon]
@="C:\\Python36\\DLLs\\py.ico"
[HKEY_CLASSES_ROOT\py_auto_file\shell\open\command]
@="\"C:\\Python36\\python.exe\" \"%1\" %*"
[HKEY_CLASSES_ROOT\Python.File]
@="Python File"
[HKEY_CLASSES_ROOT\Python.File\DefaultIcon]
@="C:\\Python36\\DLLs\\py.ico"
[HKEY_CLASSES_ROOT\Python.File\shell\open\command]
@="\"C:\\Python36\\python.exe\" \"%1\" %*"
[HKEY_CLASSES_ROOT\Python.CompiledFile]
@="Compiled Python File"
[HKEY_CLASSES_ROOT\Python.CompiledFile\DefaultIcon]
@="C:\\Python36\\DLLs\\pyc.ico"
[HKEY_CLASSES_ROOT\Python.CompiledFile\shell\open\command]
@="\"C:\\Python36\\python.exe\" \"%1\" %*"
[HKEY_CLASSES_ROOT\Python.NoConFile]
@="Python File (no console)"
[HKEY_CLASSES_ROOT\Python.NoConFile\DefaultIcon]
@="C:\\Python36\\DLLs\\py.ico"
[HKEY_CLASSES_ROOT\Python.NoConFile\shell\open\command]
@="\"C:\\Python36\\python.exe\" \"%1\" %*"
Run Code Online (Sandbox Code Playgroud)
python-2.7.0.reg
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.py]
@="Python.File"
"Content Type"="text/plain"
[HKEY_CLASSES_ROOT\.pyc]
@="Python.CompiledFile"
"Content Type"="text/plain"
[HKEY_CLASSES_ROOT\.pyw]
@="Python.NoConFile"
"Content Type"="text/plain"
[HKEY_CLASSES_ROOT\py_auto_file]
[HKEY_CLASSES_ROOT\py_auto_file\DefaultIcon]
@="C:\\Python27\\DLLs\\py.ico"
[HKEY_CLASSES_ROOT\py_auto_file\shell\open\command]
@="\"C:\\Python27\\python.exe\" \"%1\" %*"
[HKEY_CLASSES_ROOT\Python.File]
@="Python File"
[HKEY_CLASSES_ROOT\Python.File\DefaultIcon]
@="C:\\Python27\\DLLs\\py.ico"
[HKEY_CLASSES_ROOT\Python.File\shell\open\command]
@="\"C:\\Python27\\python.exe\" \"%1\" %*"
[HKEY_CLASSES_ROOT\Python.CompiledFile]
@="Compiled Python File"
[HKEY_CLASSES_ROOT\Python.CompiledFile\DefaultIcon]
@="C:\\Python27\\DLLs\\pyc.ico"
[HKEY_CLASSES_ROOT\Python.CompiledFile\shell\open\command]
@="\"C:\\Python27\\python.exe\" \"%1\" %*"
[HKEY_CLASSES_ROOT\Python.NoConFile]
@="Python File (no console)"
[HKEY_CLASSES_ROOT\Python.NoConFile\DefaultIcon]
@="C:\\Python27\\DLLs\\py.ico"
[HKEY_CLASSES_ROOT\Python.NoConFile\shell\open\command]
@="\"C:\\Python27\\python.exe\" \"%1\" %*"
Run Code Online (Sandbox Code Playgroud)
ananconda3.reg(更改用户名)
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.py]
@="Python.File"
"Content Type"="text/plain"
[HKEY_CLASSES_ROOT\.pyc]
@="Python.CompiledFile"
"Content Type"="text/plain"
[HKEY_CLASSES_ROOT\.pyw]
@="Python.NoConFile"
"Content Type"="text/plain"
[HKEY_CLASSES_ROOT\py_auto_file]
[HKEY_CLASSES_ROOT\py_auto_file\DefaultIcon]
@="C:\\Users\\username\\Anaconda3\\DLLs\\py.ico"
[HKEY_CLASSES_ROOT\py_auto_file\shell\open\command]
@="\"C:\\Users\\username\\Anaconda3\\python.exe\" \"%1\" %*"
[HKEY_CLASSES_ROOT\Python.File]
@="Python File"
[HKEY_CLASSES_ROOT\Python.File\DefaultIcon]
@="C:\\Users\\username\\Anaconda3\\DLLs\\py.ico"
[HKEY_CLASSES_ROOT\Python.File\shell\open\command]
@="\"C:\\Users\\username\\Anaconda3\\python.exe\" \"%1\" %*"
[HKEY_CLASSES_ROOT\Python.CompiledFile]
@="Compiled Python File"
[HKEY_CLASSES_ROOT\Python.CompiledFile\DefaultIcon]
@="C:\\Users\\username\\Anaconda3\\DLLs\\pyc.ico"
[HKEY_CLASSES_ROOT\Python.CompiledFile\shell\open\command]
@="\"C:\\Users\\username\\Anaconda3\\python.exe\" \"%1\" %*"
[HKEY_CLASSES_ROOT\Python.NoConFile]
@="Python File (no console)"
[HKEY_CLASSES_ROOT\Python.NoConFile\DefaultIcon]
@="C:\\Users\\username\\Anaconda3\\DLLs\\py.ico"
[HKEY_CLASSES_ROOT\Python.NoConFile\shell\open\command]
@="\"C:\\Users\\username\\Anaconda3\\python.exe\" \"%1\" %*"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
29988 次 |
| 最近记录: |