简体   繁体   中英

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?

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 (ie, the docstring of the package's init .py module) should also list the modules and subpackages exported by the package.

You could have a look at:

I would suggest not to worry about __author__ , __version__ , etc. Those attributes are handled by any decent version control system anyway. Only add them if you need to have that information on a production system, where the source code has already been exported out of the version control system.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM