[Tutor] Re: [Edu-sig] Python resources CD available [getting help() as a builtin]

Patrick K. O'Brien pobrien@orbtech.com
Sat, 9 Jun 2001 11:34:53 -0500


Just to be thoroughly anal about this whole thing, I added the following
code to my .pythonrc.py PYTHONSTARTUP file:

import __builtin__
from pydoc import help
__builtin__.help = help
del help
del __builtin__

When I go into an IDE that honors PYTHONSTARTUP, such as IDLE with the -s
command line switch, help is added to builtin and works completely fine (see
below for sample output).

I must admit, I'm not sure I understand the advantage of having help be a
builtin versus having it be just 'from pydoc import help' except that the
latter did nothing when I tried it as part of site.py. So I imagine there
are namespace things going on that I don't fully understand.

---
Here is what 'help' at the python prompt should look like:
---
>>> help

Welcome to Python 2.1!  This is the online help utility.

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://www.python.org/doc/tut/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, or topics, type "modules",
"keywords", or "topics".  Each module also comes with a one-line summary
of what it does; to list the modules whose summaries contain a given word
such as "spam", type "modules spam".

help>

---
Patrick K. O'Brien
Orbtech
"I am, therefore I think."

-----Original Message-----
From: edu-sig-admin@python.org [mailto:edu-sig-admin@python.org]On Behalf Of
Patrick K. O'Brien
Sent: Saturday, June 09, 2001 11:16 AM
To: Python-Edu SIG; tutor@python.org
Subject: RE: [Tutor] Re: [Edu-sig] Python resources CD available [getting
help() as a builtin]

I gave this a try (Adding Daniel's code to sitecustomize.py) and it didn't
quite work. Some stuff did and some didn't. As you can see from the sample
session below, help on a specific function works, but help with no
parameters does not. Weird. Daniel's code works when entered interactively
but not when loaded from sitecustomize.py. So then I tried the original
suggestion to add it to site.py and I get the same behavior. Can anyone else
confirm this? Daniel? I ran this on Win98SE with Python 2.1.

---
>>> 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

>>> help(len)
Help on built-in function len:

len(...)
    len(object) -> integer

    Return the number of items of a sequence or mapping.
>>>

---
Patrick K. O'Brien
Orbtech
"I am, therefore I think."