I'm having trouble getting command line arguments passed to Python programs if I try to execute them directly as executable commands from a Windows command shell. For example, if I have this program (test.py):
import sys
print "Args: %r" % sys.argv[1:]
And execute:
>test foo
Args: []
as compared to:
>python test.py foo
Args: ['foo']
My configuration has:
PATH=...;C:\python25;...
PATHEXT=...;.PY;....
>assoc .py
.py=Python.File
>ftype | grep Python
Python.CompiledFile="C:\Python25\python.exe" "%1" %*
Python.File="C:\Python25\python.exe" "%1" %*
Python.NoConFile="C:\Python25\pythonw.exe" "%1" %*
To make it working for me, I had to use the registry path:
and added a
%*
For Python 3.3 on Windows 7, my setting was under another registry key; the key I changed to make the arguments get passed was
HKEY_USERS\S-1-5-21-3922133726-554333396-2662258059-1000_Classes\py_auto_file\shell\open\command
It was
"C:\Python\Python33\python.exe" "%1"
. I only appended%*
to it. The key's value is now"C:\Python\Python33\python.exe" "%1" %*
.I had several (at least five) other keys with the value
"C:\Python\Python33\python.exe" "%1"
, but this is the one I changed that made it work.My setting was under yet another registry key,
HKEY_CLASSES_ROOT\py_auto_file
. The other keys mentioned also existed, but Windows was using this one for some reason.Here are .reg files to fix for Python 3.6, 2.7 and Anaconda3:
python-3.6.0.reg
python-2.7.0.reg
ananconda3.reg (change username)
Interesting. Works here using python 2.6 and Windows XP (5.1.2600):
Your program associations for
.py
files might be messed up. Just re-associate.py
files with your python executable.Right click a
.py
file >Open with
>Choose default program ...
> [find C:\PythonXY\python.exe]