making a python program in windows

Dave Angel davea at ieee.org
Thu May 21 14:54:33 EDT 2009



Rustom Mody wrote:
> I know how to make a python script behave like a (standalone) program
> in unix --
> 1. put a #! path/to/python as the first line
> 2. make the file executable
>
> The closest I know how to do this in windows is:
> r-click the file in win-explorer
> goto properties
> goto open with
> change pythonw to python
>
> Can someone enlighten me about a more scriptish way of doing this?
> Basically if I have to setup that program on other (windows) m/cs is
> there some .bat or .vbs or some regedit thingy Ive to do to avoid the
> Rt-click routine?
>
>   
Duncan told you about assoc and ftype, two programs that manipulate 
those associations (show and edit).  But one more thing you may want if 
you work much from a command line:

Look at the environment variable PATHEXT.  If it doesn't have a .PY and 
.PYW, you might want to add them.  That way when someone is typing a 
script name at the command prompt, they don't need an extension.


Anyway, now you can see two batch files you could use to make a 
particular version of Python active.  The first one uses assoc and ftype 
to fix the asssociations. And the other changes the environment variable 
PATHEXT to make the extension optional.  Note that changing the 
environment variable is effective only for that DOS box, and its 
children.  If you want a permanent change, you need to change the 
registry, probably at
   hklm\SYSTEM\ControlSet001\Contro/Session\Session 
Manager\Environment\PATHEXT


This can be automated either with a .REG file, or with a few lines of 
Python code that manipulates the registry.  The latter is better, 
because you can avoid disturbing the other extensions that will already 
be there.


You can also manipulate the registry to get SendTo items on the context 
menu for .PY files, and so on.





More information about the Python-list mailing list