python调用exe无法传递参数_Windows无法将参数传递给python脚本

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

now going command-line, on my winXP platform:

d:\path\py_script.py 1 2

yields

first arg is 1

second arg is 2

yet on my Win7 platform I get

no args

If I do

d:\path\python py_script.py 1 2

I get

first arg is 1

second arg is 2

How can I make my Win7 environment act as expected ?

some details:

win7 is 64bit.

py2.6.6 on win7, py 2.6.4 on winXP.

解决方案

Based on jtp's answer.

Well I messed up with the registry a bit.

This was what I think are the steps:

doing

assoc .py=Python.File

through win explorer pick a .py file, right click -> x64 -> open with > browse to c:\Python26\python.exe choose the 'always open with this..' box.

this in effect changes immediately the reg value

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts.py\UserChoice

to

Python.File

set HKEY_CLASSES_ROOT\Python.File\shell\Open\Command to

"C:\Python26\python.exe" "%1" %2 %3 %4 %5 %6 %7 %8 %9

note: from previous experience i'm sure things are expected to mess up with mixed versions.

uninstalling/re-installing shall be the way to go. BTW, I didn't want to go through that becuase with all the packages including ones I built from source it would be a mess.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值