Difference between revisions of "Python: Module Header Example"

From RHS Wiki
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 
* The first two lines of each file shoud be  
 
* The first two lines of each file shoud be  
  <nowiki># -*- coding: utf-8 -*-
+
  <nowiki>#!/usr/bin/env python
#!/usr/bin/env</nowiki>
+
# -*- coding: utf-8 -*-</nowiki>
 
+
* Make sure to link /usr/bin/env to your virtualenv bin folder
 
* 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.<br />
 
* 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.<br />
 
https://www.python.org/dev/peps/pep-0257/
 
https://www.python.org/dev/peps/pep-0257/

Latest revision as of 09:58, 2 April 2017

  • The first two lines of each file shoud be
#!/usr/bin/env python
# -*- coding: utf-8 -*-
  • Make sure to link /usr/bin/env to your virtualenv bin folder
  • 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.

https://www.python.org/dev/peps/pep-0257/

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