Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable Python shell spawning less with "help"

Tags:

python

shell

Title says it all. I'd prefer that Python's shell use cat instead of less when displaying help so that the contents of help is inline with the rest of the shell session.

like image 321
datajerk Avatar asked Oct 04 '14 16:10

datajerk


2 Answers

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.

like image 106
Lukas Graf Avatar answered Oct 30 '22 08:10

Lukas Graf


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.

like image 30
jkuzeja Avatar answered Oct 30 '22 06:10

jkuzeja