How to disable Python shell spawning "less" with "help"

Solution 1:

This also seems to work:

>>> import pydoc
>>> pydoc.pager = pydoc.plainpager

This works even if you have already invoked the help command, as it replaces the cached version in pydoc.py.

Solution 2:

The help() function seems to respect the PAGER environment variable. So the following works for me to switch to cat as the pager instead of less:

PAGER=cat python
>>> import os
>>> help(os)

You can also change the environment variable from inside Python:

>>> import os
>>> os.environ['PAGER'] = 'cat'
>>>
>>> help(os)

But note that this will only have an effect if you do this before the first time you use the pager, because the pager is cached in pydoc.py after the first time it has been determined.