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

Patrick K. O'Brien pobrien@orbtech.com
Sat, 9 Jun 2001 10:18:41 -0500


Here is the code in site.py that attempts to load sitecustomize.py. As you
can gather, sitecustomize.py will have to be on the PYTHONPATH in order to
be found, which limits where the file can be located.

#
# Run custom site specific code, if available.
#
try:
    import sitecustomize
except ImportError:
    pass

Site.py lives in the Lib directory, so that might be one place to put
sitecustomize.py. I don't like that because I like to keep customizations
separate from standard Python stuff. So I will probably put this into one of
my own personal directories. But that doesn't work as a standard approach.

Now that I've played with this I actually like Daniel Yoo's original
suggestion the best. Maybe someone should suggest to Guido and company that
Daniel's change to site.py be added to the standard distribution. There is
something of a precedent in that site.py includes some code to define
responses to some other terms (see code below). Anyone know how to submit a
PEP?

--- 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
Orbtech
"I am, therefore I think."

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

Cool idea. Could I suggest a small change, though? The documentation for
site says this:

"After these path manipulations, an attempt is made to import a module
named sitecustomize, which can perform arbitrary additional
site-specific customizations.  If this import fails with an
ImportError exception, it is silently ignored."

So would it make more sense to create a sitecustomize.py file with your
code? I'm going to give it a try, as soon as I have another cup of coffee.

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