Windows无法将参数传递给python脚本 [英] Windows fails to pass the args to a python script

查看:386
本文介绍了Windows无法将参数传递给python脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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 

产生

  first arg is 1 
second arg is 2

然而在我的Win7平台上, / p>

 没有args 


$ b b

如果我这样做

  d:\path\python py_script.py 1 2 

我得到

 arg is 1 
second arg is 2

如何让我的Win7环境?



一些细节:

win7是64位。

py2.6.6在win7上,py 2.6.4在winXP上。

解决方案

基于jtp的回答。

好​​了,我搞砸了注册表。 >

这是我认为的步骤:


  1. assoc .py = Python.File


  2. 通过win explorer选择一个.py文件, x64 - >打开与>浏览到c:\Python26\python.exe选择总是打开这个..框。
    这实际上会立即改变reg值



    HKEY_CURRENT_USER\软件\Microsoft\Windows \CurrentVersion\Explorer\FileExts.py\ UserChoice

    Python.File


  3. 将HKEY_CLASSES_ROOT\Python.File\shell\Open\Command设置为
    C:\Python26\python.exe%1%2%3%4%5%6%7%8%9

注意:从以前的经验,我敢肯定的事情预计混乱的混合版本。
卸载/重新安装应该是要走的路。 BTW,我不想经历,因为所有的包,包括我从源码构建它将是一团糟。


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:

  1. doing

    assoc .py=Python.File

  2. 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

  3. 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.

这篇关于Windows无法将参数传递给python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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