Telling python where to look for a script

Alex Martelli aleaxit at yahoo.com
Thu Jun 14 06:00:36 EDT 2001


"Brian Elmegaard" <brian at rk-speed-rugby.dk> wrote in message
news:3B285BFD.D2AC7E26 at rk-speed-rugby.dk...
> Hi,
>
> I would like to make python aware of where my scripts are located. I
> have set pythonpath to \python20\scripts, but I can imagine how this
> could be filled up by numerous scripts over time, so can python search
> it recursively?
>
> I also tried to copy the way it is done by pmw, which is found, but is
> not in any pythonpath? Can I do it the same way and how is it done?

There is an important difference between scripts and
modules.  A script is meant to be run as an argument
to python.exe (assuming you're on Windows because of
the backslashes:-).  A module is meant to be imported.
A foo.py file can be both, but adapting the path is
relevant to module-use only, NOT to script-use.  All
clear so far...?

For sys.path adaptation, simplest is to use .PTH files.

Any textfile with an extension of .PTH found in the
Python home directory (e.g. C:\Python20 in your case,
I guess) is read on startup: each line is the full
path of a directory to be added to sys.path (the .PTH
file may also include empty lines and comment lines
starting with #).


Alex






More information about the Python-list mailing list