直接调用带参数的关联脚本

2024-09-24 22:26:42 发布

您现在位置:Python中文网/ 问答频道 /正文

在Windows控制台中,如果执行此脚本(test.py):

import sys
print(sys.argv)

比如:

>python test.py my args

我得到了预期的结果:

['test.py', 'my', 'args']

但如果我直接这么说:

>test.py my args

我得到:['C:\\temp\\test.py']输出,好像我没有传递任何参数。为什么

仅供参考:

>assoc | findstr .py=
.py=Python.File

>ftype Python.File
Python.File=C:\Python35\python.exe "%1" %*

Tags: pytestimport脚本参数mywindowssys
1条回答
网友
1楼 · 发布于 2024-09-24 22:26:42

与讨论here类似,您需要确保command键设置正确。在我的windows10副本上,我发现有两个地方的commandreg设置为"C:\Python27\python.exe" "%1" %*

HKEY_CLASSES_ROOT\Python.CompiledFile\shell\open\command
HKEY_CLASSES_ROOT\Python.File\shell\open\command

我想首先要检查这两把钥匙

相关问题 更多 >