[Python-Dev] Relative import

Guido van Rossum guido at python.org
Wed Dec 17 23:55:03 EST 2003

> I'll just note that where the current status quo trips /me/ up most is
> when I accidentally have a local module with the same name as a global
> module, and then I write an import statement expecting to get the
> standard library module, but end up getting the local module.

This can be interpreted in two ways though.  You could be unfortunate
enough to create a module in your package that has the same name as a
standard module you also need to import from inside the same package
-- that's currently impossible.  But the most common variant I've seen
is what Tim Peters describes: having a module in the current directory
that accidentally hides a standard module.

The latter case does not involve packages and will not be fixed by any
import syntax -- it can only be fixed by changing the default sys.path
*not* to include the current directory, just like over the last decade
or so Unix shells have stopped putting '.' in $PATH.

But that has other downsides: it would be a lot harder to begin
writing a program broken up into modules.  Hmm, maybe the current
directory should be last?  That way you can import your own modules
except if they clash with the standard library.  Hm, but there are so
many standard library modules that it might still cause frequent
complaints from mystified beginners.

I'm beginning to agree (uselessly) with Tim: import itself is a
problem. :-)

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

More information about the Python-Dev mailing list