Customizing the python search path depending on source directory

Peter Hansen peter at engcorp.com
Tue Apr 6 23:03:42 EDT 2004


Peter Schwalm wrote:

> My idea was to use site.py / sitecustomize.py in lib/site-packages and
> to have sitecustomize.py invoke a directory-specific customizing
> module - say dirCustomize.py - located in the script source directory.
> 
> But it seems that this is the wrong place, because at the moment
> sitecustomize is imported
> 
>     a) the source directory of the script is still not in sys.path

Are you sure?  Looking at site.py, it appears that the sitecustomize
import is done next-to-last, just before sys.setdefaultencoding is
deleted.  If you concluded this by examining sys.path manually at
the point just as sitecustomize is imported, maybe you don't know
that the '' entry in sys.path actually represents the source
directory of the main script...

It would seem your suggested solution above should actually work...

-Peter



More information about the Python-list mailing list