Search code examples
pythondocumentationpython-module

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?


Solution

  • 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/