Python Script does not take sys.argv in Windows

烂漫一生 提交于 2019-12-18 04:45:09

问题


I have two computers with Windows, and I just found that on one of them, if I ran python code directly, like:

test_args.py input1 input2

Python will not recognized the input I gave, but this works:

python test_args.py input1 input2

I tried the code:

import sys

print 'Number of arguments:', len(sys.argv), 'arguments.'
print 'Argument List:', str(sys.argv)

And the first way(test_args.py) returns:

Number of arguments: 1 arguments.
Argument List: ['D:\\Test\\args\\test_args.py']

While the sceond way (python test_args.py input1 input2) returns:

Number of arguments: 3 arguments.
Argument List: ['D:\\Test\\args\\test_args.py', 'input1', 'input2']

Any idea on what this could happen? This issue only happens in one of my computers, both have same version of Windows.

Thanks!

SOLVED:

I search in regedit keyword "python" and found two keys missing %* after "C:\Python27\python.exe" "%1":

Computer\HKEY_CLASSES_ROOT\Applications\python.exe

Computer\HKEY_CLASSES_ROOT\py_auto_file\shell\open\command

And .py is associated with py_auto_file even though I tried assoc .py Python.File

Changing the two keys fixed this issue, thanks!


回答1:


Check what is the association of *.py files on these two computers. The script may be executed by different Python interpreters.



来源:https://stackoverflow.com/questions/29540541/python-script-does-not-take-sys-argv-in-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!