在 py_script.py 中:
import os
import sys
l = len(sys.argv)
if l == 1:
print 'no args'
else:
if l > 1:
print 'first arg is %s'%sys.argv[1]
if l > 2:
print 'second arg is %s'%sys.argv[2]
现在在我的 winXP 平台上使用命令行:
d:\path\py_script.py 1 2
yields
first arg is 1
second arg is 2
但在我的Win7平台上我得到
no args
If I do
d:\path\python py_script.py 1 2
I get
first arg is 1
second arg is 2
如何让我的Win7环境达到预期的效果?
一些细节:
win7是64位的。
win7 上为 py2.6.6,winXP 上为 py 2.6.4。
我在 Win 7 上使用 2.7.1。
如果您想仅通过文件扩展名调用Python程序,您应该检查文件类型关联和命令行参数。我在 Windows 上安装/重新安装多个版本的 Python 时遇到了问题。
C:\dv>assoc .py
.py=Python.File
C:\dv>ftype Python.File
Python.File="C:\Python27\python.exe" "%1" %*
此 TechNet 页面可以提供一些更详细的背景信息。
http://technet.microsoft.com/en-us/library/bb490912.aspx http://technet.microsoft.com/en-us/library/bb490912.aspx
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)