Feed Sign in with OpenID OpenID

Simon Willison’s Weblog

Pydoc

Pydoc is awesome; I don’t know how I missed it for so long. Simply type the following at the command line:

pydoc -p 8888

Then point a browser at http://localhost:8888/ to browse interactive documentation for every Python module available on your system. This includes moduldes installed in your site-packages directory. If you keep code you’ve written yourself in site-packages you’ll be able to browse the documentation for that too. If you’re even remotely consistent about writing docstrings you’ll be amazed at how useful the resulting documentation is. I can’t believe I only just discovered this!

This is Pydoc by Simon Willison, posted on 23rd March 2004.

View blog reactions

Next: Quicksilver

Previous: Zend PHP 5 Goodies

15 comments

  1. Wow, that is amazing... I can't believe I'd never heard of it before either!

    One additional note - since the current directory is always in your python path, if the directory you're in when you run pydoc contains modules or packages, you'll get the documentation for them too.

    Abe - 23rd March 2004 23:14 - #

  2. Yep, it's cool. I have it start in my "~/.kde/Autostart" as "pydoc.sh":

    export PYTHONPATH=/home/richard/src/roundup/roundup
    /usr/bin/pydoc -p 8888 &

    Adding the additional PYTHONPATH entry means that my in-development Roundup code is also added to the pydoc pages.

    Richard - 23rd March 2004 23:55 - #

  3. just don't look at the markup it generates... ugh. nested tables and font tags galore.

    anders - 24th March 2004 06:44 - #

  4. Pydoc is also responsible for the magic invoked when you type help(), help(object) or help('module') in the interactive interpreter. It’s not as good looking, but help(type(s)) may be even more useful than the webserver.

    Carey Evans - 24th March 2004 06:48 - #

  5. Python is a huge amount of fun to work with. It's like one of the countless goth chicks (pardon my German) on OKCupid.com: at first, they look pretty scary, but then you realize they're really kinky and do things you didn't know were possible, making you a much happier person.

    Actually, let's not go there.

    Hendrik Mans - 24th March 2004 09:41 - #

  6. And doctests are handy too:
    http://www.python.org/doc/current/lib/module-docte st.html

    duncan - 24th March 2004 15:28 - #

  7. Hmmph. I like the idea of docs being testable (and therefore closer to reality), but wouldn't the syntax guessing be brittle? And wouldn't you end up re-developing an xUnit framework to address problems like mocks and stateful tests?

    Worth thinking about, though.

    Jeremy Dunck - 24th March 2004 15:38 - #

  8. Wow, I never cease to be amazed by python.

    For those windows users out there you may have to be more specific.

    From the DOS prompt type:

    python.exe pydoc.py -p 8888

    If that still doesn't work include the full path to both python.exe and/or pydoc.py and you should be set.

    waylman - 24th March 2004 21:19 - #

  9. Windows users can also use pydocgui.pyw in \Tools\Scripts\ so it also easy to search the documentation.

    Ewald van Houte - 25th March 2004 14:03 - #

  10. Unrelated to this entry, but I noticed that under IE6, there's a JavaScript error occurring.

    Line 3, Expected ')'.

    I took the time to look at what's causing it.

    You're including Technorati's script in the head section. The problem is that it embeds the site's name in the alt attribute of the technorati image-- and the single quote in your site name is breaking the javascript string.

    Technorati needs to escape the value in it's alt attribute. "Simon Willison\'s Weblog", not "Simon Willison's Weblog". Shorter-term, you might avoid the error by changing the site name in Technorati.

    I figured you'd have better luck getting Technorati to do their tweak.

    Jeremy Dunck - 25th March 2004 22:39 - #

  11. If you use KDE, you can get Konqueror to show pydoc-generated documentation by entering URLs of the form pydoc:<module> in the location bar.

    It's one of those features in Konqueror that deserves to get a lot more publicity. ;-)

    David Boddie - 5th April 2004 11:31 - #

  12. It's smart too. If you have multiple versions of python installed:

    $ which pydoc
    /usr/bin/pydoc
    $ python2.1 /usr/bin/pydoc -p 8881 &
    [1] 10852
    $ pydoc server ready at http://localhost:8881/

    $ python2.2 /usr/bin/pydoc -p 8882 &
    [2] 10864
    $ pydoc server ready at http://localhost:8882/

    $ python2.3 /usr/bin/pydoc -p 8883 &
    [3] 10865
    $ pydoc server ready at http://localhost:8883/

    Peter van Kampen - 5th April 2004 17:24 - #

  13. I played around with the markup for a little bit, I think it looks a lot better now. I've posted about it on my weblog since I don't know if I can just release the modified source.

    Manuzhai - 29th September 2004 16:39 - #

  14. Since the pydoc module is in the module search path, you don't have to specify its location; you can specify it as a module to be imported.

    python.exe -m pydoc -p 8888
    

    Ben Finney - 5th August 2005 03:02 - #

  15. pydoc is awsome, and I really like it I was wondering if anyone knows how to add search capability to the page generated by pydoc.org it is really helpful , if i can search the docstrings for a perticular keyword thanks clive

    Clive - 9th September 2005 02:23 - #

Comments are closed.

Previously hosted at http://simon.incutio.com/archive/2004/03/23/pydoc

A django site