Author eryksun
Recipients eryksun, nedbat
Date 2014-06-01.18:13:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1401646421.79.0.481680641586.issue21625@psf.upfronthosting.co.za>
In-reply-to
Content
> Why does help() enter a more-mode for even short help?  

`more` exits if there's less than a page of a text. The default for `less` is to quit when "q" is entered. You may be interested in the option -e (quit-at-eof).

> Why doesn't ENTER get you out of it?  

ENTER scrolls. Type a number N to scroll by N lines.

> Why does it clear the screen when you are done with it, 
> removing all the help from the screen?

The option -X (no-init) should stop `less` from clearing the screen.

> Why doesn't the prompt have a suggestion of how to get out of it?  

I guess no one thought to add that when `less` is used.

You can customize the pager using the PAGER environment variable, as used by other commands such as `man`.

    $ PAGER='less -eX' python3 -c 'help(help)'
    Help on _Helper in module site object:
    
    class _Helper(builtins.object)
    [...]

You can also set pydoc.pager directly, which is what IDLE does:

    >>> pydoc.pager = pydoc.plainpager
    >>> help(help)
    Help on _Helper in module site object:
    [...]

plainpager is the default if the TERM environment variable is dumb or emacs, or if sys.stdout isn't a tty. Otheriwse if the system has neither `less` nor `more`, the pager is set to pydoc.ttypager. 

On Windows, text is written to a temp file using tempfilepager. Other platforms pipe the text using pipepager. This should also work for Windows in Python 3, which implements os.popen with subprocess.Popen. Here's a test using GnuWin32 head.exe and tr.exe:

    >>> cmd = 'head -n3 | tr [:lower:] [:upper:]'    
    >>> pydoc.pager = lambda t: pydoc.pipepager(t, cmd)
    >>> help(help)
    HELP ON _HELPER IN MODULE _SITEBUILTINS OBJECT:
    
    CLASS _HELPER(BUILTINS.OBJECT)
History
Date User Action Args
2014-06-01 18:13:41eryksunsetrecipients: + eryksun, nedbat
2014-06-01 18:13:41eryksunsetmessageid: <1401646421.79.0.481680641586.issue21625@psf.upfronthosting.co.za>
2014-06-01 18:13:41eryksunlinkissue21625 messages
2014-06-01 18:13:41eryksuncreate