Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python > Save help() output to formated html file?

I have a very long output from help() function and found it a bit hard to find what I am looking for in the script editor. Is it possible to save the help() output as a formatted html file?

like image 569
bwv656 Avatar asked Feb 27 '16 20:02

bwv656


2 Answers

Yes, you can use the pydoc module to do this in the Python interpreter:

import pydoc
pydoc.writedoc("sys")

This code will write the documentation for the sys module to a file sys.html in the current directory. If you want to get documentation for a package, you need to use pydoc.writedocs() instead.

The Python docs say that you can also run pydoc -w <object> from the command line, but this didn't work for me without including the full path:

C:\Python27\Lib\pydoc.py -w sys
like image 116
tjohnson Avatar answered Sep 29 '22 10:09

tjohnson


another option that may be worth mentioning is: redirect the standard output to a file, but this will give you a text file instead of a html

for example

import sys
with open("range help.txt","w") as archi:
    t = sys.stdout
    sys.stdout = archi
    help(range)
    sys.stdout = t
like image 24
Copperfield Avatar answered Sep 29 '22 11:09

Copperfield