3

In some templates and code examples of Python modules, I see that the __init__.py files contain variable declarations like these:

__title__ = 'example'
__version__ = '1.0.0'
__author__ = 'Just Me'
__license__ = 'MIT'
__copyright__ = 'Copyright 2016 by Me'

I could not find any official documentation mentioning them though.

Do those declarations have any effect, e.g. when packaging and distributing the module, or are these values basically equal to comments?

Should I add any of them to my projects, is this considered good style? Which ones? Is there a complete list of standardized variables like those?

Byte Commander
  • 6,506
  • 6
  • 44
  • 71
  • Well, during package cration you *can* import that module and take the values from there. Also providing such variables is strictly better then simple comments because in this way the attributes can be accessed from the REPL. – Bakuriu Jun 23 '16 at 10:48
  • 8
    See also [`__version__` in PEP-396](https://www.python.org/dev/peps/pep-0396/), [example with `__version__` and `__author__` in PEP-8](https://www.python.org/dev/peps/pep-0008/#module-level-dunder-names), etc. Also, FWIW, I've written a helper to parse them out of the module and use them in `setup.py`, in case the module can't be imported prior to install (missing requirements, etc.): https://github.com/textbook/atmdb/blob/master/setup.py#L19 – jonrsharpe Jun 23 '16 at 10:53
  • @jonrsharpe I like your comment, can you convert it to an answer ? – SebMa Sep 08 '17 at 05:39
  • pep 396 was rejected. You should not use `__version__` in modules – Thomas Grainger May 08 '21 at 15:30

0 Answers0