Shebang or Hashbang for modules or not?
Ben Finney
bignose+hates-spam at benfinney.id.au
Wed Apr 11 17:49:09 EDT 2007
"Chris Lasher" <chris.lasher at gmail.com> writes:
> I recently heard someone argue that shebangs were only appropriate
> for Python code intended to be executable (i.e., run from the
> command line).
Since that's the purpose of putting in a shebang line, that's what I'd
argue also; specifically:
- Modules intended primarily for import should be named 'foo.py' and
have no shebang line.
This doesn't preclude having an 'if __name__ == "__main__":'
block, and running the module as 'python ./foo.py' for whatever
reason.
- Modules intended primarily for running as a command should have a
shebang line and an 'if __name__ == "__main__":' block, and be
named according to the conventions of the OS for naming command
programs; on *nix, this means naming the file 'foo'.
This doesn't preclude importing the module (e.g. for unit
testing), though it is a little more convoluted than a simple
'import' statement.
--
\ "Dad always thought laughter was the best medicine, which I |
`\ guess is why several of us died of tuberculosis." -- Jack |
_o__) Handey |
Ben Finney
More information about the Python-list
mailing list