Python: Module Header Example

From RHS Wiki
Revision as of 09:03, 2 April 2017 by Rafahsolis (talk | contribs) (Created page with "* The first line of each file shoud be #!/usr/bin/env python. This makes it possible to run the file as a script invoking the interpreter implicitly, e.g. in a CGI context. *...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
  • The first line of each file shoud be #!/usr/bin/env python. This makes it possible to run the file as a script invoking the interpreter implicitly, e.g. in a CGI context.
  • Next should be the docstring with a description. If the description is long, the first line should be a short summary that makes sense on its own, separated from the rest by a newline.
  • All code, including import statements, should follow the docstring. Otherwise, the docstring will not be recognized by the interpreter, and you will not have access to it in interactive sessions (i.e. through obj.__doc__) or when generating documentation with automated tools.
  • Import built-in modules first, followed by third-party modules, followed by any changes to the path and your own modules. Especially, additions to the path and names of your modules are likely to change rapidly: keeping them in one place makes them easier to find.
  • Next should be authorship information. This information should follow this format:
__author__ = "Rafael Herrero Solís [,other authors] "
__copyright__ = "Copyright 2017, Herrerosolis.com"
__credits__ = ["Rafael Herrero Solís"[, "Colab 1", "Colab 2", ...]
__license__ = "GPL"
__version__ = "1.0.1"
__maintainer__ = "Rafael Herrero Solís"
__email__ = "rafael@herrerosolis.com"
__status__ = "Production"
  • __status__ Status should typically be one of "Prototype", "Development", or "Production".
  • __maintainer__ should be the person who will fix bugs and make improvements if imported.
  • __credits__ differs from __author__ in that __credits__ includes people who reported bug fixes, made suggestions, etc. but did not actually write the code.