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

James C. Ahlstrom jim@interet.com
Tue, 27 Nov 2001 08:18:37 -0500


"Martin v. Loewis" wrote:
> 
> > 2) The addition of sys.path[0] is changed to an earlier
> >    time so it occurs before any imports; so sys.path[0]
> >    works the same as sys.path[1:].  Currently it is added
> >    after some imports have occurred.
> 
> I still try to finding the same mental picture for this as you
> apparently have. I understand "changed to an earlier time".
> 
> What I don't understand is the effect that you associate with it:
> sys.path[0] is a string, sys.path[1:] is a list. In what sense do they
> "work the same"?

They work the same in that imports are satisfied from the items.
sys.path[0] is the first directory string, sys.path[1:] are the
remaining strings.  Imports are satisfied from sys.path.
The timing is currently as follows:

1) Create an initial sys.path but without its first item.
2) Import site, os, sitecustomize, etc.
3) Insert a new item as sys.path[0].

Therefore the new sys.path[0] will not be used to satisfy an
import of the os module because it has already been imported.

The new timing would be:

1) Create all items in sys.path.
2) Import site, os, sitecustomize, etc.

Therefore the new sys.path[0] will be available to satisfy an
import of the os module.

JimA