Windows – How to set file association in Windows Explorer

file-typespythonwindows 7

I have installed the Canopy Python package, and when I double-click a python file it opens the Canopy editor. I want clicking the file to run it, not edit it. I have changed the file properties to Type of file: PY file (.py) / Opens with: python.exe but it doesn't work. Double clicking the file flashes a cmd window for a split second but does not run the file, presumably because it's starting python without giving it a filename.

Note: in a cmd window, python file.py runs the file just fine. And assoc .py says .py=Enthought.Canopy, not the expected something like .py=pyfile.

Note2: Association of Python files in Windows not working says to do a "shift right-click" on the file, but I get no better options with the shift than with just a right-click by itself.

The properties window has no obvious way to tell Windows to run the file with python.exe %s, which is what I assume is needed. How does one set a file association that will actually run the file?

Best Answer

New versions of Windows require Registry editing since the file association control panel does not allow you to specify parameter passing. One source suggests using this in a text file saved as "foo.reg" and opened by Windows:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Perl\shell\Open\command] @="\"C:\path\to\python.exe\" \"%1\" %*"

This should cause Windows to pass the filename to the interpreter.

Source: https://stackoverflow.com/questions/444388/how-can-i-pass-command-line-arguments-via-file-association-in-vista-64

Related Question