Windows无法将args传递给python脚本

Han*_*nan 2 python windows command-line windows-7

在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]
Run Code Online (Sandbox Code Playgroud)

现在我的winXP平台上的命令行:

d:\path\py_script.py 1 2
Run Code Online (Sandbox Code Playgroud)

产量

first arg is 1
second arg is 2
Run Code Online (Sandbox Code Playgroud)

但是在我的Win7平台上,我得到了

no args
Run Code Online (Sandbox Code Playgroud)

如果我做

d:\path\python py_script.py 1 2
Run Code Online (Sandbox Code Playgroud)

我明白了

first arg is 1
second arg is 2
Run Code Online (Sandbox Code Playgroud)

如何让Win7环境按预期运行?

一些细节:
win7是64bit.
win7上的py2.6.6,winXP上的py 2.6.4.

T.P*_*.P. 5

我在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" %*
Run Code Online (Sandbox Code Playgroud)

此TechNet页面可以提供更详细的背景信息.

http://technet.microsoft.com/en-us/library/bb490912.aspx