Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there conventions for Python module comments?

It is my understanding that a module docstring should just provide a general description of what a module does and details such as author and version should only be contained in the module's comments.

However, I have seen the following in comments and docstrings:

__author__ = "..."
__version__ = "..."
__date__ = "..."

Where is the correct location to put items such as these? What other __[name]__ variables are common to list at the top of modules?

like image 977
Jace Browning Avatar asked Sep 03 '10 13:09

Jace Browning


People also ask

What are different type of commenting styles in Python?

What Are the Different Types of Comments in Python? There are three types of comments: single-line, multi-line, and docstring comments.

What are conventions in Python?

Convention means a certain way in which things are done within a community to ensure order. Similarly, Coding conventions are also a set of guidelines, but for a programming language that recommends programming style, practices, and methods.

How do you write comments in Python?

A comment in Python starts with the hash character, # , and extends to the end of the physical line. A hash character within a string value is not seen as a comment, though. To be precise, a comment can be written in three ways - entirely on its own line, next to a statement of code, and as a multi-line comment block.

Where do you put comments in Python?

Comment Syntax Comments in Python begin with a hash mark ( # ) and whitespace character and continue to the end of the line.


2 Answers

They are merely conventions, albeit quite widely-used conventions. See this description of a set of Python metadata requirements.

__version__ is mentioned in the Python Style Guide.

Regarding docstrings, there's a PEP just for you!

The docstring for a module should generally list the classes, exceptions and functions (and any other objects) that are exported by the module, with a one-line summary of each. (These summaries generally give less detail than the summary line in the object's docstring.) The docstring for a package (i.e., the docstring of the package's init.py module) should also list the modules and subpackages exported by the package.

like image 183
Katriel Avatar answered Oct 27 '22 20:10

Katriel


You could have a look at:

  • Epydoc, more specifically its pre-defined fields.
  • Pydoc
like image 29
Bruno Avatar answered Oct 27 '22 21:10

Bruno