How do I make python scripts executable?

On Windows 2000 and XP, the standard Python installer already
associates the .py extension with a file type (Python.File) and gives
that file type an open command that runs the interpreter (D:\Program
Files\Python\python.exe “%1” %*). This is enough to make scripts
executable from the command prompt as ‘foo.py’. If you’d rather be
able to execute the script by simply typing ‘foo’ with no extension
you need to add .py to the PATHEXT environment variable.

On Windows NT, the steps taken by the installer as described above
allow you to run a script with ‘foo.py’, but a longtime bug in the NT
command processor prevents you from redirecting the input or output of
any script executed in this way. This is often important.

The incantation for making a Python script executable under WinNT is
to give the file an extension of .cmd and add the following as the
first line: