Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I document a module in Python?

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?

like image 625
Auron Avatar asked Sep 04 '08 16:09

Auron


People also ask

How do you write a Python module document?

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.

How do you describe a module in Python?

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.

What is module docs in Python?

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.


2 Answers

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.

like image 171
Brad Koch Avatar answered Sep 18 '22 08:09

Brad Koch


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/

like image 23
Grégoire Cachet Avatar answered Sep 18 '22 08:09

Grégoire Cachet