Discussion:
[python-win32] argument passing problem on Windows 7 64-Bit
Tony Cappellini
2015-07-31 23:37:38 UTC
Permalink
Hello,

I've got Python 2.7.10 64-Bit installed, via the Anaconda installer

The path clearly shows C:\Anaconda in the path. Typing python by
itself brings up
the python REPL as expected.

Running this simplified program easily illustrates the problem I'm seeing
in another, larger Python program.

http://pastebin.com/0bjBLgDh

Running that script as:
python cmdline.py 1 2 3
shows the expected output -> Cmd line args: ['cmdline.py', '1', '2', '3']

Running that script as -> cmdline.py 1 2 3
shows this output ->Cmd line args:
'C:\\Users\\tonycappellini\\Projects\\cmdline\\cmdline.py']

Searching for help yielded these,
http://superuser.com/questions/429604/passing-arguments-to-a-python-script-file-association-not-found-windows-7-on-i
https://technet.microsoft.com/en-us/library/bb490912.aspx


I found that assoc .py
showed this ->File type 'Python.File' not found or no open command
associated with it

ftype Python.file
shows python.file="c:\Anaconda\python.exe" "%1" %*

So, I've added this association for .py files
assoc .py=Python.file

and rebooted

assoc .py
now shows .py=Python.file

However, arguments are still not being correctly passed to Python files.

I am stumped by this issue, as it has never been a problem for me in
the ~10 years that I've been using Python n Windows.
I am working at a new job where all development systems use Windows 7
64-Bit. The systems at my previous place of employment used Windows 7
32-Bit,
but I wouldn't expect this kind of problem from moving to a 64-But OS.

I would appreciate some help understanding and fixing this issue,

Thanks
Dennis Lee Bieber
2015-08-01 16:45:33 UTC
Permalink
Post by Tony Cappellini
Hello,
I've got Python 2.7.10 64-Bit installed, via the Anaconda installer
Older ActiveState install here...
Post by Tony Cappellini
Running this simplified program easily illustrates the problem I'm seeing
in another, larger Python program.
http://pastebin.com/0bjBLgDh
Considering that the simplest program I envision is only three lines,
putting it inline with the post is most appropriate...

C:\Users\Wulfraed\Documents\Python Progs>type commandline.py
import sys
for i, a in enumerate(sys.argv):
print "%5d\t'%s'" % (i, a)


C:\Users\Wulfraed\Documents\Python Progs>python commandline.py a 2 3 f
0 'commandline.py'
1 'a'
2 '2'
3 '3'
4 'f'

C:\Users\Wulfraed\Documents\Python Progs>commandline.py 1 t r 4
0 'C:\Users\Wulfraed\Documents\Python Progs\commandline.py'
1 '1'
2 't'
3 'r'
4 '4'

C:\Users\Wulfraed\Documents\Python Progs>commandline x y 99
0 'C:\Users\Wulfraed\Documents\Python Progs\commandline.py'
1 'x'
2 'y'
3 '99'

C:\Users\Wulfraed\Documents\Python Progs>assoc .py
.py=Python.File

C:\Users\Wulfraed\Documents\Python Progs>ftype Python.File
Python.File="C:\Python_x64\Python27\python.exe" "%1" %*

C:\Users\Wulfraed\Documents\Python Progs>set pathext
PATHEXT=.py;.pyw;.EXE;.COM;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

C:\Users\Wulfraed\Documents\Python Progs>

You may have to cruise the registry with an editor as it is possible
there is some left-over registry key that is not be seen by assoc/ftype but
IS being used by the OS, and that registry key may not have the %* on the
command template. See midway down:

http://www.perlmonks.org/?node_id=1054513

(Obviously you'd have to look for a python command invocation, not perl)
--
Wulfraed Dennis Lee Bieber AF6VN
***@ix.netcom.com HTTP://wlfraed.home.netcom.com/
Tony Cappellini
2015-08-03 20:20:23 UTC
Permalink
Dennis,
Post by Dennis Lee Bieber
C:\Users\Wulfraed\Documents\Python Progs>ftype Python.File
Python.File="C:\Python_x64\Python27\python.exe" "%1" %*
This appears to have fixed my problem.
I am now seeing output similar to yours, that is, the same output in both cases.


I am curious how this issue came to be. I don't just edit the
registry, because I don't
know what to add/remove/change.


Thank You!

Loading...