I have Python 2.5 installed on Windows XP and a collection of scripts available in a certain directory. According to this article by Amanda Birmingham I can setup up a path for the Python executable and the one for where the scripts live. Which means I can do this:
c:\>python script.py
Is there a way I can perhaps register .py files so I can execute them like so:
c:\>script.py
without including a shebang or env line in the script.
Less typing equals good. :)
Yes :) That's actually FAQ #2:
Edit: Of course, don't forget to add the Python install directory to the PATH, and to launch another instance of your command interpreter if you modify the systemwide or the user PATH and/or PATHEXT by means outside of that command interpreter.
Further edit: In case I misunderstood your question: I'm assuming you're only interested in launching python scripts without having to type in the .py extension from the cmd.exe command line. PATHEXT is a mechanism specific to the cmd.exe shell and other shells (as well as
CreateProcess()
and friends) won't care about it in the least.I had exactly the same issue with PHP.
http://php.net/manual/en/install.windows.legacy.index.php#install.windows.legacy.commandline (Edit: Seems command line usage for PHP is now "legacy")
One thing that I found was being able to use PHP scripts as filters ...
(for example - where scripts\script is a PHP script - NOTE : No PHP reference).
The registry change is required for this. Works for all of those interpreter type languages on windows (PHP, Python, Perl, Ruby).
PATHEXT will allow you to leave off ".py", but that's not what you are asking, right?
If you want to associate a file extension with an application on Windows, you can:
These are instructions for XP. I presume that Vista and Win7 are basically the same, although you probably get to the list in some other way.