import confused by contents of working directory

greg greg at cosc.canterbury.ac.nz
Sat Jun 3 11:00:23 CEST 2006


Jon wrote:
> It appears that (windows) python searches in the current working
> directory before looking in the local site-packages directory, or that
> '.' comes first in sys.path?

Unless it behaves very differently on Windows from
everything else, this isn't quite true. The current
directory is only put in the path when using the
interpreter interactively. When you do

   python somefile.py

the directory containing somefile.py is put at the
beginning of sys.path, not the current directory.
So you'd still have the same problem even if you
weren't cd'ed to the directory containing the test
program.

The moral is not to put your test program in the
same directory as your package files. (Or if you
must, have it delete sys.path[0] before importing
anything.)

--
Greg



More information about the Python-list mailing list