Empty sys.path[0]

Peter Hansen peter at engcorp.com
Sat Jul 7 18:22:25 CEST 2001


Gustaf Liljegren wrote:
> 
> Michal Wallace <sabren at manifestation.com> wrote:
> 
> >Where do the docs say this? It sounds like a mistake, or something
> >that needs clarification..
> 
> In the library reference, for the 'path' list in the 'os' module: "The
> first item of this list, path[0], is the directory containing the script
> that was used to invoke the Python interpreter." I interpreted it as the
> directory with the script.

I think you mean the "sys" module above, not the "os" module.  I didn't
know about this behaviour with sys.path[0] until now, but when I tested
it under Windows it worked as documented.  If I invoke a script in 
a different directory, sys.path[0] shows the directory.  If I invoke
the script in the current directory, sys.path[0] shows the empty string.
(Other notes in the documentation point out the special behaviour if
you invoke the interpreter interactively etc).

So if you have a script containing

import sys
print sys.path

and you run it from another directory (e.g. 'python c:\windows\test.py'
or 'python /tmp/test.py' what do you get?

-- 
----------------------
Peter Hansen, P.Eng.
peter at engcorp.com



More information about the Python-list mailing list