1

Mine is the same basic question as this, but the answers there don't help me.

Given this Python script, argv.py:

import sys

if __name__ == '__main__':
    print sys.argv

If I execute it with python argv.py foo it displays ['argv.py', 'foo'].

If I execute it with argv.py foo it displays ['M:\\Projects\\SomaLogic\\CmdLine\\argv.py']. What I expected here was ['foo'].

The result of assoc .py is .py=Python.File.

The result of ftype Python.File is Python.File="C:\Python27.10\python.exe" "%1" %*.

EDIT: added expectation for the failing case.

Community
  • 1
  • 1
Mike C
  • 1,224
  • 10
  • 26
  • 1
    It's never going to be ['foo'] because the 0th arg is always supposed to be the script. Not entirely clear where the rest of your args are disappearing to, though. – pvg Mar 28 '17 at 20:42
  • 1
    http://eli.thegreenplace.net/2010/12/14/problem-passing-arguments-to-python-scripts-on-windows seems to have better luck by changing the registry – pvg Mar 28 '17 at 20:44
  • Is `%*` the right flag? I seem to remember that being something different but it's been a while since I've been on Windows. Plus you can use `py argv.py foo` so it's not a load of extra characters that you have to type... – Wayne Werner Mar 28 '17 at 20:48
  • @WayneWerner, that's how it's [documented](https://docs.python.org/2/faq/windows.html#id3) – Mike C Mar 28 '17 at 20:55
  • Good enough for me :) – Wayne Werner Mar 28 '17 at 20:58
  • @pvg, thanks. The registry change does fix the problem. I don't get why the assoc+ftype configuration doesn't yield the same thing. Now I have to untangle which of my Pythons, if any, are from ActiveState; I didn't think I'd installed that on my machine. (The customer, however, does use ActiveState.) – Mike C Mar 28 '17 at 21:06
  • You might consider bundling your entire environment with something like py2exe if your goal is actual distribution to random machines. It's a whole other can of worms but at least you'll only have to do it locally once. – pvg Mar 28 '17 at 21:10

0 Answers0