Is the first entry in sys.path supposed to represent the current working directory?

672 Views Asked by At

I had always assumed that the first entry in sys.path by default was the current working directory. But as it turns out, on my system the first entry is the path on which the script resides. So if I'm executing a script that's in /usr/bin from /some/directory, the first entry in sys.path is /usr/bin. Is something misconfigured on my system, or is this the expected behavior?

2

There are 2 best solutions below

0
Yuval Adam On BEST ANSWER

This is by design:

As initialized upon program startup, the first item of this list, path[0], is the directory containing the script that was used to invoke the Python interpreter.

source: http://docs.python.org/library/sys.html#sys.path

1
Ned Batchelder On

You can get the current directory with os.getcwd().