Shebang or Hashbang for modules or not?

Jorgen Grahn grahn+nntp at snipabacken.dyndns.org
Fri Apr 13 06:54:18 EDT 2007


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.

> 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. 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.

  I realise that you took a more narrow view than I do above, 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, and so
  I am a bit oversensitive ...

>> 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.
I always use both.

/Jorgen

-- 
  // Jorgen Grahn <grahn@        Ph'nglui mglw'nafh Cthulhu
\X/     snipabacken.dyndns.org>  R'lyeh wgah'nagl fhtagn!



More information about the Python-list mailing list