Customizing the python search path depending on source directory

Peter Hansen peter at engcorp.com
Wed Apr 7 09:11:34 EDT 2004


Peter Schwalm wrote:

> Peter Hansen <peter at engcorp.com> wrote in message news:> >
> Thank you for your answer. But I'm afraid it's not the source
> directory but the current working directory. You can see the
> difference if you copy the passage
> 
>     "for ix1, p1 in enumerate(sys.path): print "%02.02d: %s" % (ix1,
> p1)"
> 
> to a "normal script". If you start that "normal script" from a
> directory other than the source directory, you can see that both
> directories are included in sys.path. If you run this code inside
> sitecustomize.py this is not the case.

On the contrary.  When I start that from another directory which
is *not* in the path, I do not see that directory in the sys.path
at all, but merely the directory in which the script itself is
stored.  This is the defined behaviour of the Python sys.path
stuff and you must be misinterpreting something.

The current directory is *not* added to sys.path, unless it
just happens that the main script is in the current directory.

-Peter



More information about the Python-list mailing list