Shebang or Hashbang for modules or not?

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Fri Apr 13 22:46:03 CEST 2007


Jorgen Grahn a écrit :
> On Thu, 12 Apr 2007 00:24:12 +0200, Bruno Desthuilliers <bdesth.quelquechose at free.quelquepart.fr> wrote:
> 
>>Chris Lasher a écrit :
>>
>>>Should a Python module not intended to be executed have shebang/
>>>hashbang (e.g., "#!/usr/bin/env python") or not?
>>
>>The shebang is only useful for files that you want to make directly 
>>executable on a *n*x system. They are useless on Windows,
> 
> 
> Probably (unless setup.py uses them for something meaningful there,
> too). But of course often you don't know that the file will always be
> used only on Windows, or that the Windows user won't prefer Cygwin.

 From a practical POV, I consider cygwin as a *n*x system. And FWIW, I 
mentionned this platform specificness because it might not be clear to 
anyone reading the OP.

> 
>>and not 
>>technically required to use the file as a main program  -ie: you can 
>>always run it like this:
>>$ /path/to/python filename.py
> 
> 
> You can, but sometimes it's not appropriate.

That's another question. What I meant here is that you don't technically 
need the shebang and x bit to allow execution of a Python file. IOW, the 
shebang is only meaningfull for python files intented to be effectivly 
used as a program.

> If you distribute a
> Python program to Unix users in that form, they may not want to know
> or care which language it's written in. Especially if you decide, a
> few releases later, that you want to switch to Perl or something.

<troll>
No one in it's own mind would decide to switch from Python to Perl !-)
</troll>

More seriously, and as far as I'm concerned, when I want to make a 
python script (by opposition to a python 'module') available as a unix 
command, I either use a symlink or a shell script calling the python 
script.

>   I realise that you took a more narrow view than I do above,

I mostly tried to answer the OP question.

> so
>   please see this as additional notes rather than critisism. It's just
>   that I am struggling with people at work who feel program names
>   should encode whatever language they happen to be written in,

OMG.

> and so
>   I am a bit oversensitive ...

I can understand this...

> 
>>>I'm used to having a
>>>shebang in every .py file
>>
>>An encoding declaration might be more useful IMHO !-)
> 
> 
> They are not mutually exclusive, if that is what you mean.

Of course not. But one is always usefull (and will become more or less 
mandatory in a near future IIRC), while the other is either totally 
useless (module files) or only partially useful (script files).

> I always use both.

Even in modules ?????



More information about the Python-list mailing list