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.
import pydoc
help_result_string = pydoc.render_doc(obj)
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.
Details on what other things can happen when help(obj)
is called can be found in the pydoc source code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With