Related Entries

India PyCon 2009
Quick wallpaper changer
Load testing with Grinder
Adding namespace to XML
Opera RSS to OPML

« CompMail: Send HTML mail
» Nagios

Joy of Python: Self documenting code

Very very newbie information on how to document your Python code easily and generate HTML documentation.

I had read about PyDoc, a tool like JavaDoc to create html documentation for your python code. Today I downloaded the code and tried it out. It is very good. It is a small script that I urge you to start using, if you are not already using.

Personally, now there is no excuse for me, to not write doc strings for functions and classes. This is a very small code that hopefully help Python newbies to start writing code and then generate documentation, with HTMLized source code too.

Here’s the code in text format - code_doc.py.

Generating color coded HTMLized version
First get py2html.py. Then run py2html.py your_python_file.py. This will create the file your_python_file.py.html.
See the HTML version of code_doc.py.
Generating class documentation
Run pydoc -w your_python_file.your_python_function_or_class. The output will be in your_python_file.your_python_function_or_class.html.
Here’s the output of me running pydoc -w code_doc.Vehicle.

To get some starter information on where Python stores the documentation strings, see the code!

  1. As of (I think) Python 2.2, pydoc is part of the standard library - you don't need to download it separately.

    Posted by: Simon Brunning on September 10, 2002 03:23 AM
//-->