Windows中Python脚本不采用sys.argv [英] Python Script does not take sys.argv in Windows

查看:125
本文介绍了Windows中Python脚本不采用sys.argv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两台装有Windows的计算机,但我发现其中一台是直接运行python代码的,例如:

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无法识别我提供的输入,但这可以:

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

python test_args.py input1 input2

我尝试了代码:

import sys

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

第一种方式(test_args.py)返回:

And the first way(test_args.py) returns:

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

虽然以这种方式(python test_args.py input1 input2)返回:

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']

关于这可能发生什么的任何想法?
此问题仅发生在我的一台计算机上,两台计算机的Windows版本相同。

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

谢谢!

我在regedit关键字 python中搜索,发现在 C:\Python27\python.exe之后发现缺少%*的两个键1:

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

计算机\HKEY_CLASSES_ROOT\应用程序\python.exe

Computer\HKEY_CLASSES_ROOT\Applications\python.exe

计算机\HKEY_CLASSES_ROOT\ \py_auto_file\shell\open\命令

Computer\HKEY_CLASSES_ROOT\py_auto_file\shell\open\command

即使我尝试assoc .py Python.File

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

更改两个键可解决此问题,谢谢!

Changing the two keys fixed this issue, thanks!

推荐答案

检查*的关联是什么这两台计算机上的.py文件。该脚本可由不同的Python解释器执行。

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

这篇关于Windows中Python脚本不采用sys.argv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆