[Python-Dev] Re: Change to sys.path[0] for Python 2.3

James C. Ahlstrom jim@interet.com
Tue, 27 Nov 2001 09:14:29 -0500


Jack Jansen wrote:
> 
> > 4) For the "-c" option, sys.argv[0] is getcwd() instead of "".
> 
> A related issue: what is sys.path[0] for an interactive interpreter? I
> customarily use Python as a shell, and os.chdir() from one place to another,
> importing things along the way. Would an interactive interpreter keep the ""
> entry in sys.path[0]?

The proposal is to put getcwd() into sys.path[0] for an interactive
interpreter.  So after os.chdir(), imports would NOT be made from
the new current directory, but rather from the original current
directory.

If this is a problem (I'm guessing it is) then the new rule would be:

   sys.path[0] is the absolute path to the script if there is one; else
   for an interactive interpreter or for the "-c" option, sys.path[0]
   is the special entry "" (or perhaps ".") that means look in the
   current directory (which is allowed to change).

In either case, sys.path[0] would be added before any imports.

I am not happy with changing current directories because I am trying
to speed up imports, and it is harder to cache directory contents
on multiple operating systems.  But I can do it if we need to.

A special case for "." is not too bad, but accommodating arbitrary
relative paths is more of a problem.

What do others think?

JimA