How to guard against bugs like this one?

Carl Banks pavlovevidence at gmail.com
Tue Feb 2 19:38:53 CET 2010


On Feb 2, 9:02 am, Nobody <nob... at nowhere.com> wrote:
> I don't know if that's necessary. Only supporting the "foo.h" case would
> work fine if Python behaved like gcc, i.e. if the "current directory"
> referred to the directory contain the file performing the import rather
> than in the process' CWD.
>
> As it stands, imports are dynamically scoped, when they should be
> lexically scoped.

Mostly incorrect.  The CWD is in sys.path only for interactive
sessions, and when started with -c switch.  When running scripts, the
directory where the script is located is used instead, not the
process's working directory.

So, no, it isn't anything like dynamic scoping.


> The only situation where the process' CWD should be used is for an import
> statement in a non-file source (i.e. stdin or the argument to the -c
> switch).

It already is that way, chief.

I think you're misunderstanding what's wrong here; the CWD doesn't
have anything to do with it.  Even if CWD isn't in the path you still
get the bad behavior kj noted.  So now what?

Python's importing can be improved but there's no foolproof way to get
rid of the fundamental problem of name clashes.


Carl Banks



More information about the Python-list mailing list