[Tutor] windows and python and shebangs, oh my!

Alan Gauld alan.gauld at btinternet.com
Thu Apr 5 10:27:38 CEST 2007


"Kirk Bailey" <deliberatus at verizon.net> wrote

> OK, in a script, we include a special statement telling the shell 
> where
> to go find the interpeter. This is the first line of the script, and 
> is
> a dpecial sort of comment, called informally the shebang.

Yes, but it is not a Python feature it is a Unix thing.
When you execute a script (of any kind) in Unix the Unix
shell(*) reads the first line and if its a shebang transfers
control to the appropriate interpreter.

(*) And not all Unix shells adhere to the convention,
but thankfully the vast majority do. The SVR4 Bourne
shell didn't as I recall.

> In windows, this is for the current edition C:\python25\pythonw.exe
> so the shebang is
> #!C:\python\pythonw.exe

This is often done purely as a convention that shows what
version of Python the script was created for.
Python does nothing with it, it is only a comment.

> At a loss, it then occurred to me that the program is a .py name
> extension. When the auto installer installed python it may have 
> created
> an association between that name extension and the correct 
> interpreter
> automatically,

Correct, or you can do it manually. tHat is the only way that Windows
associates files with commands.

> So work with me, windows Pythonistas. CAN I rely on windows 
> definitely
> and reliably having .py files associated with the windows python
> interpreter,

No, the association can be changed by any user or install script.

But in practice it rarely is changed so you can habe a good chance of 
success.
If you really want to be sure the associations are stored in the 
registry.
You can look them up and change them (or add a missing one) as you 
need.

> If so, my task of designing the autoinstaller script just got a LOT 
> simpler.

On Windows the answer is usually in the registry somewhere, you
just need to figure out where to look!

Alan G. 




More information about the Tutor mailing list