the module load path

graham.matthews@maths.anu.edu.au
1 Feb 1995 23:40:17 GMT

Is there a way to add directories to the module load path? I tried
appending to sys.path, but that didn't work since its read only. The
reason I ask this question is that I seem to have got caught with a
nasty interaction between sys.path and os.chdir().

[the following is an educated guess at what is happening - please
correct me if wrong]

I start a Python application in a directory D. D contains a number of modules
that my application will use. My application merrily imports these modules
using the fact that sys.path contains "." by default, and "." is D.
However one of my modules executes an os.chdir() to "..". Now when
Python attempts to import any module in D, it cannot since "." in
sys.path is no longer D, it is "../D". This is particularly annoying
when the module that executes the os.chdir() also pops up a window W,
and grabs the X11 input focus to be W (for example the module implements
a modal dialog box). In this case Python stops with its error message, but
there is no way to 'cont' it since the focus is still stuck in W!

One solution to this is to allow the user to set to module load path. This
would allow me to set an absolute path for D in sys.path. It also allows me
to organise my Python code better, as I can have libraries of code in
different directories.

graham

--
                      Je suis pour le communisme
                      Je suis pour le socialisme
                      Je suis pour le capitalisme
                     Parce que je suis opportuniste