[Idle-dev] Weird error when pydoc.help is added to builtin from site.py

Guido van Rossum guido@digicool.com
Tue, 12 Jun 2001 10:05:02 -0400


> Here is a problem we discovered on the python-edu list. We are trying to add
> pydoc help to the python environment by adding the following code to
> site.py:
> 
> from pydoc import help
> import __builtin__
> __builtin__.help = help
> del help
> del __builtin__
> 
> For the most part this works. For example, in IDLE, you can do help(len) and
> get the expected information. But try help with no value and you get the
> following:
> 
> >>> help
> Traceback (most recent call last):
>   File "<interactive input>", line 1, in ?
>   File "c:\python21\lib\pydoc.py", line 1276, in __repr__
>     self()
>   File "c:\python21\lib\pydoc.py", line 1285, in __call__
>     self.interact()
>   File "c:\python21\lib\pydoc.py", line 1297, in interact
>     self.output.flush()
> IOError: [Errno 9] Bad file descriptor

Hm, this works for me in Python 2.2a0.  Which versions of Python, IDLE
and pydoc are you using?  Perhaps you have to reserach the problem
more to find out what's the matter.  Could it be the PAGER environment
variable?

> Any idea what the problem might be? And if we can get it to work, how do you
> feel about introducing this as a PEP for Python? There is something of a
> precedent in the existing code that defines "quit" and "exit". So it would
> seem to make sense to define "help" as well.
> 
> --- snipped from site.py as support for PEP XXXXX ---
> 
> # Define new built-ins 'quit' and 'exit'.
> # These are simply strings that display a hint on how to exit.
> if os.sep == ':':
>     exit = 'Use Cmd-Q to quit.'
> elif os.sep == '\\':
>     exit = 'Use Ctrl-Z plus Return to exit.'
> else:
>     exit = 'Use Ctrl-D (i.e. EOF) to exit.'
> import __builtin__
> __builtin__.quit = __builtin__.exit = exit
> del exit
> 
> ---
> Patrick K. O'Brien

There are some problems with doing it this way: the pydoc module is
too big to be imported by site.py.  Ping has suggested that some kind
of lightweight 'bootstrap' code should be included in site.py.  I am
in favor of that, but I'm waiting for someone else to submit a
patch...

--Guido van Rossum (home page: http://www.python.org/~guido/)