That's it. If you want to document a function or a class, you put a string just after the definition. For instance:
def foo(): """This function does nothing.""" pass
But what about a module? How can I document what a file.py does?
For the modules, you can add a docstring simply in the module file. Show activity on this post. Here is an Example Google Style Python Docstrings on how module can be documented. Basically there is an information about a module, how to execute it and information about module level variables and list of ToDo items.
In Python, Modules are simply files with the “. py” extension containing Python code that can be imported inside another Python Program. In simple terms, we can consider a module to be the same as a code library or a file that contains a set of functions that you want to include in your application.
Such a file is called a module; definitions from a module can be imported into other modules or into the main module (the collection of variables that you have access to in a script executed at the top level and in calculator mode). A module is a file containing Python definitions and statements.
Add your docstring as the first statement in the module.
""" Your module's verbose yet thorough docstring. """ import foo # ...
For packages, you can add your docstring to __init__.py
.
For the packages, you can document it in __init__.py
. For the modules, you can add a docstring simply in the module file.
All the information is here: http://www.python.org/dev/peps/pep-0257/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With