[Tutor] sys.path and the path order
steve at pearwood.info
Fri Apr 23 05:42:43 CEST 2010
On Fri, 23 Apr 2010 10:34:02 am Garry Willgoose wrote:
> My question is so simple I'm surprised I can't find an answer
Did you read the Fine Manual?
> I'm interested if I can rely on the order of the
> directories in the sys.path list.
> The question is can I rely on entry  in sys.path always being the
> directory in which the original file resides (& across linux, OSX and
The documentation says:
A list of strings that specifies the search path for modules.
Initialized from the environment variable PYTHONPATH, plus an
As initialized upon program startup, the first item of this list,
path, is the directory containing the script that was used to invoke
the Python interpreter. If the script directory is not available (e.g.
if the interpreter is invoked interactively or if the script is read
from standard input), path is the empty string, which directs Python
to search modules in the current directory first. Notice that the
script directory is inserted before the entries inserted as a result of
So the answer to your question is, Yes.
More information about the Tutor