[Python-Dev] Re: Change to sys.path[0] for Python 2.3
Tommy 'Too Many Stances' Burnette
tommy@ilm.com
Tue, 27 Nov 2001 09:43:42 -0800 (PST)
James C. Ahlstrom writes:
|
| 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?
|
As little as I like it, we have lots and lots of code here that
depends on chdir to find modules for importing. If you were to make
this change (and I suspect you won't because it might break lots of
code, but for argument's sake...) would having an explicit '.'
somewhere in sys.path still work after a chdir?