开发者

Python command line options fail on one account, but not on another

I am running on Windows Server 开发者_运维问答2008. We use Python extensively on several servers, and for the most part it works well. However, on at least one server, arguments don't get passed to my python scripts when I run from a command line. If I log on as a different user, the script works as expected. I can also run the script in the Eclipse IDE with arguments with no problems.

I will do something like this:

myscript.py -h

or

\Python2.6\python.exe myscript.py -h

Rather than display the help, it runs with the default arguments.

If I recall correctly (this has been a problem for a while, so my memory is fuzzy), this account used to run these scripts without a problem.


If you start a Python script, e.g.:

import sys
for a in sys.argv:
  print a

with plain

showargs.py a b c

the effective call is controlled by registry settings witch can be checked with ftype

ftype Python.File
Python.File="C:\Python25\python.exe" "%1" %*

The %* is crucial for passing the arguments to the script. If the %* is missing,

ftype Python.File="C:\Python25\python.exe" "%1"
Python.File="C:\Python25\python.exe" "%1"

showargs.py
<no output>

the script does not see any arguments. This ftype setting should not affect explicit calls:

python showargs.py a b c
showargs.py
a
b
c

but "python" on your system/in your IDE could possibly call the 'real' python.exe in a roundabout way - thereby being affected by the ftype settings too. So use ftype for a quick check and/or look at the specification for the "run python script" in your IDE.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜