Skip to content
This repository has been archived by the owner on Jun 30, 2023. It is now read-only.

Latest commit

 

History

History
30 lines (24 loc) · 820 Bytes

Cookbook:-Sending-built-in-help-to-the-pager.mediawiki

File metadata and controls

30 lines (24 loc) · 820 Bytes

IPython's %pinfo (?) and %pinfo2 (??) interactive help commands use the pager to avoid flooding the shell with long blocks of text.

Here is a magic command to give the same behavior to Python's built-in (pydoc) help command (tested in Python 2.7):

from IPython.core import page
def magic_help(self, s):
    """Retrieve the pydoc help for an object and display it through a pager.

    See http://stackoverflow.com/a/1176180/1410871
    """
    import pydoc
    import sys
    obj = reduce(getattr, s.split("."), sys.modules[__name__])
    page.page(pydoc.plain(pydoc.render_doc(obj)))

ip = get_ipython()
ip.define_magic("help",magic_help)

After running this code from the interactive prompt or via your local config settings, you can send help through the pager like so:

import re
%help re