Thursday, January 27, 2011

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?

  • It's easy, you just add a docstring at the top of the module.

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

  • You do it the exact same way. Put a string in as the first statement in the module.

  • Ok, thank you for your quick answers :)

    From Auron

0 comments:

Post a Comment