This is a problem I encountered more than once, and today I finally found a "solution". I place "solution" in quotes because it's more of a workaround for something that seems to be a problem of the Python Windows installer.

I ran into the problem on a Windows 7 box running ActivePython 2.6, but according to this Python issue, others have encountered the problem with Windows XP and Python 3.x as well.

The problem manifests itself as follows. Prepare a simple script containing:

import sys
print sys.argv

Execute it from the command-line:

C:\>python z.py 1 2 3
['z.py', '1', '2', '3']

This looks right. But now execute it without prepending python:

C:\>z.py 1 2 3
['C:\\z.py']

What gives? Doesn't the installer configure .py files to be run by the Python executable correctly, passing arguments to it as one would expect?

Now, I found a couple of non-solutions. The most popular was to setup the association with the assoc and ftype commands, as follows:

C:\>ftype Python26.File="C:\Python26\python.exe" "%1" %*
C:\>assoc .py=Python26.File

But at no avail, the problem persisted.

What eventually solved it is fixing the relevant registry keys for Python. I set the HKEY_CLASSES_ROOT\Applications\python26.exe\shell\open\command key to:

"C:\Python26\python26.exe" "%1" %*

Previously, %* was missing. Similarly, I set HKEY_CLASSES_ROOT\py_auto_file\shell\open\command to the same value. You can also set it accordingly for python26w.exe (the no-shell version of Python on Windows).

This worked, and now I got:

C:\>z.py 1 2 3
['C:\\z.py', '1', '2', '3']

What causes the problem? In all likeness the ActivePython 2.6 installer, which doesn't set up the registry keys correctly. Now, this may not always happen, and some discussions point to it being dependent on other factors. For instance, I had another version of Python already installed on the machine when I executed the installer - this may have confused it.