How to print module documentation in Python

You can use the .__doc__ attribute of the module of function:

In [14]: import itertools

In [15]: print itertools.__doc__
Functional tools for creating and using iterators..........

In [18]: print itertools.permutations.__doc__
permutations(iterable[, r]) --> permutations object

Return successive r-length permutations of elements in the iterable.

permutations(range(3), 2) --> (0,1), (0,2), (1,0), (1,2), (2,0), (2,1)

Both of help() and __doc__ work fine on both inbuilt and on our own modules:


def myfunc():
    this is some info on myfunc


In [4]: help(so27.myfunc)

In [5]: import foo

In [6]: print foo.myfunc.__doc__

     this is some info on func

In [7]: help(foo.myfunc)

Help on function myfunc in module foo:

    this is some info on func

Leave a Comment