How do I export the output of Python's built-in help() function

ipmcc picture ipmcc · Jun 29, 2012 · Viewed 9.2k times · Source

I've got a python package which outputs considerable help text from: help(package)

I would like to export this help text to a file, in the format in which it's displayed by help(package)

How might I go about this?

Answer

Aaron Altman picture Aaron Altman · Jun 29, 2012

pydoc.render_doc(thing) to get thing's help text as a string. Other parts of pydoc like pydoc.text and pydoc.html can help you write it to a file.

Using the -w modifier in linux will write the output to a html in the current directory, for example;

pydoc -w Rpi.GPIO

Puts all the help() text that would be presented from the command help(Rpi.GPIO) into a nicely formatted file Rpi.GPIO.html, in the current directory of the shell