[Python-Dev] PythonCore\CurrentVersion

Guido van Rossum guido at python.org
Tue Oct 11 18:22:43 CEST 2005

On 10/11/05, Tim Peters <tim.peters at gmail.com> wrote:
> [Tim]
> >> Well, that's in interactive mode, and I see sys.path[0] == "" on both
> >> Windows and Linux then.  I don't see "" in sys.path on either box in
> >> batch mode, although I do see the absolutized path to the current
> >> directory in sys.path in batch mode on Windows but not on Linux -- but
> >> Mark Hammond says he doesn't see (any form of) the current directory
> >> in sys.path in batch mode on Windows.
> >>
> >> It's a bit confusing ;-)
> [Guido]
> > How did you test batch mode?
> I gave full code (it's brief) and screen-scrapes from Windows and
> Linux yesterday:
>     http://mail.python.org/pipermail/python-dev/2005-October/057162.html
> By batch mode, I meant invoking
>     path_to_python   path_to_python_script.py
> from a shell prompt.
> > All:
> >
> > sys.path[0] is *not* defined to be the current directory.
> >
> > It is defined to be the directory of the script that was used to
> > invoke python (sys.argv[0], typically).
> In my runs, sys.argv[0] was the path to the Python executable, not to
> the script being run.

I tried your experiment but added 'print sys.argv[0]' and didn't see
that. sys.argv[0] is the path to the script.

> The directory of the script being run was
> nevertheless in sys.path[0] on both Windows and Linux.  On Windows,
> but not on Linux, the _current_ directory (the directory I happened to
> be in at the time I invoked Python) was also on sys.path; Mark Hammond
> said it was not when he tried, but he didn't show exactly what he did
> so I'm not sure what he saw.

I see what you see.  The first entry is the script's directory, the
2nd is a nonexistent zip file, the 3rd is the current directory, then
the rest is standard library stuff.

I suppose PC/getpathp.c puts it there, per your post quoted above?

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-Dev mailing list