[Windows] drag-and-drop onto .py file in modern versions?

Chris Angelico rosuav at gmail.com
Thu Apr 12 03:00:54 EDT 2012


On Thu, Apr 12, 2012 at 4:02 PM, Karl Knechtel <zahlman at gmail.com> wrote:
> Aside: when I double-click a .py file, what determines which Python will run
> it? Is it a matter of which appears first in the PATH, or do I have to set
> something else in the registry? Will a shebang line override the default on
> Windows? If so, how do I write a shebang line for a Windows path - just
> "#!C:/Windows/Python32"?

Apologies - I can't answer your main question, and am just picking up the aside.

The file-type association (which is really a file-extension
association) determines the path to the executable. If that's
specified without a full path, then it'll be the first one in PATH,
but usually the association is given as an absolute filespec. I don't
have a Vista handy, but in XP, bring up any folder, Options|Folder
Options, File Types, and scroll down to PY. (For some obscure reason,
on this particular computer of mine the association is with a Python
that was installed with GNU Lilypond. Weird!) You may need to use the
Advanced button to see the full path.

As to writing a shebang, there's no way to do that directly. But in
theory you could associate .py files with a little script that reads
the first line and figures out which interpreter to invoke it in. For
extra coolness points, write that script in portable Python that can
be run on any of the interpreters you have installed - then you don't
have to care! :)

Chris Angelico



More information about the Python-list mailing list