Q:

How to write help() documentation to a file Python?

So I was looking at the help() documentation of a module but soon realized it was very tedius to read the documentation in the small output box. So therefore I tried pasting the help() documentation to another file for more clearer reading.
myfile = open("file.txt","w") 
myfile.write(str(help(random)))
myfile.close()

Instead of the documentation being written, it instead pasted in None.
Any ideas how to do this?

A:

The answer is pydoc!. Run it from the console:
$ pydoc [modulename] > file.txt

and it will basically write the output of the help() command to file.txt

A:

i'm not suggesting you should read the python documentation this way - but here is what you could do: you could redirect stdout and call help:
from contextlib import redirect_stdout
import random

with open('random_help.txt', 'w') as file:
    with redirect_stdout(file):
        help(random)

or, even simpler (as suggested by Jon Clements):
from pydoc import doc
import random

with open('random_help.txt', 'w') as file:
    doc(random, output=file)

