[Python-Dev] sys.path[0]

Thomas Heller theller@python.net
07 Jan 2003 22:11:45 +0100


[Kevin Altis brought this to my attention, so I'm cc-ing him]

The python docs state on sys.path:

  As initialized upon program startup, the first item of this list,
  path[0], 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[0] is the empty
  string, which directs Python to search modules in the current
  directory first.

This is at least misleading.

It appears that for certain ways Python is started, the first item
on sys.path is a relative path name, or even empty, even if a script
was specified, and the path would have been available.

This leads to problems if the script changes the working directory.
Not always because the programmer explicitely called os.chdir(),
also 'behind the scenes' when a GUI is used.

Shouldn't Python convert sys.path to absolute path names, to avoid
these problems?

Thomas