[Tutor] sitecustomize and pythonstartup

Christopher Smith csmith@blakeschool.org
Fri, 01 Feb 2002 16:26:47 -0600


I've been trying to learn what behaviors can be automated at start up and
have come up with the following which might be useful for others. 
Corrections are welcome.  It also raises a question that I ask below.

---

_____
A script can 

	import user

which will run the script ".pythonrc.py" if it exists in the same
directory as the script.  Objects in .pythonrc.py (imported modules,
function definitions, or variables) are accessible to the calling script
by using the "user." prefix.  For example, if math has been loaded in
.pythonrc.py, the main program can access math.pi as user.math.pi  {see
user.py}

_____
The Python IDE will attempt to load a file named sitecustomize.pyc if it
exists on the paths defined by sys.path.  No objects therein (modules,
functions, variables) are accessible to the IDE interactive console or
scripts, but changes to variables like sys.path can be made. If there is
any printing done in the file, this will create a window titled "Python
IDE.out" which can be moved and resized but not closed.  {see site.py and
the file sitecustomize.py}

_____
The Python Interpreter will attempt to run the sitecustomize.pyc script if
it exists on the paths defined by sys.path.  No objects therein (modules,
functions, variables) are accessible to the IDE interactive console or
scripts.

The Interpreter will also attempt to import and run the contents of a file
named PythonStartup if it exists on in the same directory as the
interpreter.  Objects in PythonStartup are then accessible directly to the
interpreter (e.g. if "import math" appears in PythonStartup then typing
"math.pi" in the interpreter will yield the value of pi).  Commands like
"from __future__ import division" will not affect the Interpreter,
however, and must be reimported there.  If PythonStartup imports a module
A which in turn imports a module B, B's namespace must be accessed as
A.B.name. {see section "Interactive startup file" in the using.html file
in the Mac:Demo folder.




-------

OK, the question is this.  The interpreter can be educated as to what
modules are loaded (i.e. if pythonstartup imports math, you can type
math.pi in the interpreter and be understood).  Is there a way to get this
to happen in the IDE's interpreter as well?  If sitecustomize.py imports
math I can't seem to access that at the >>> prompt.

Also, is there a way to get "from __future__ import division" to be the
default behavior in the interpreter?  This statement in the startup file
does not create the floating integer behavior in the IDE's interpreter or
in the Python Interpreter itself.

/c