What should Python apps do when asked to show help?

Steven D'Aprano steve at pearwood.info
Fri Apr 29 23:23:40 EDT 2016


On Sat, 30 Apr 2016 12:49 pm, Ben Finney wrote:

> Random832 <random832 at fastmail.com> writes:
> 
>> On Fri, Apr 29, 2016, at 22:27, Rustom Mody wrote:
>> > Instead it does some ½-assed fall-between-the-stools of both
>>
>> That doesn't answer the question of why, if you (Well, Ethan, but
>> you're taking the same position here) hate pagers so much
> 
> That's not a question relevant here; nobody inthe discussion has a
> position fairly characterised as “hate pagers so much”. So you're
> arguing against a straw man.
> 
> Rather, the position being argued is that they *do* like pagers; they
> like pagers enough that they want the existing ‘PAGER’ environment
> variable setting to remain untouched. 

So they want the PAGER environment variable to specify what pager they
want...

> And, simulatenously, they want 
> Python's help to not use a pager at the interactive prompt.

...so long as applications don't actually make use of that PAGER environment
variable to determine the pager they want to use.


(1) If you want man, and nothing else in the universe, to automatically use
a pager, then set MANPAGER="less" (or whatever you wish to use), and unset
PAGER.


(2) If you don't want *anything* to use a pager, then unset both MANPAGER
and PAGER. You may have to report a feature request / bug report for
applications which force their own pager.


(3) In Python specifically, you can trivially and easily tell help() to
output directly to stdout. (At least on Linux, I haven't tested it
elsewhere.) Simply use PAGER=cat on the command line you use to launch the
interactive environment. This will affect no other running or future
processes (apart from subprocesses launched from your interactive Python
session), allowing you to keep your PAGER for everything else.

(4) If you want more than that, then patches are welcome :-)


Seriously, I'm thinking that a keyword argument to help might be useful:

help(object, pager=None)

where:

- pager=None gives the current behaviour;

- pager="foo" calls out to the external program "foo";

- pager=callable passes the help text to callable().


pager=print would do exactly what people are asking for, and you could then
create your own wrapper to change the default:

help = functools.partial(builtins.help, pager=print)


I think that would make it easier to test help(). Thoughts?



-- 
Steven




More information about the Python-list mailing list