Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)
I'd like to get help(obj) text in IPython or Jupyter notebook in a non-interactive manner, into some variable instead of it being displayed.

Note: help provides more information than obj.__doc__ provides, so that's not quite an alternative.

1 Answer

0 votes
by (36.8k points)
edited by

Short way:

import pydoc

help_result_string = pydoc.render_doc(obj)

Long way:

When you call help(obj), it is a wrapper to pydoc.help(obj) (see help.__doc__), which is the same as pydoc.Helper()(obj) (from pydoc source: help = Helper()), which usually leads to pydoc.doc(obj), which writes the resulting string from pydoc.render_doc(obj) to the standard output or a pager, depending on the system.

If you are a beginner and want to know more about Data Science the do check out the Data Science course

Browse Categories

...