[Python-Dev] Relative vs. absolute imports

Bernhard Herzog bh at intevation.de
Wed May 19 14:53:21 EDT 2004


Guido van Rossum <guido at python.org> writes:

>> > Because in the current situation the meaning of an import is
>> > ambiguous.
>> 
>> What exactly is ambiguous about it?
>
> Looking at "import foo" you can't tell whether there's a module foo
> expected in the current package or in the top-level module namespace.

Well, looking at "print foo" I can't tell whether its a local variable,
a global variable or a builtin either.  Nobody's going to suggest we
should introduce special syntax to distinguish them, I hope.  Module
import isn't much different and it's only a little harder to figure out
whether its a relative import or not, and you only have to distinguish
them when the importer is a module in a package. 

I've been using packages in the current form ever since they've been
introduced in Python 1.5.  In all that time, relative imports have never
been a problem for me, IIRC, and I use them for all sibling imports.

Absolute imports have their own difficulties, too, btw, and relative
imports don't add much complexity on top of that.  I don't think the
ambiguity, if you want to call it that, is enough of a problem to
justify the incompatibility.

   Bernhard

-- 
Intevation GmbH                                 http://intevation.de/
Skencil                                http://sketch.sourceforge.net/
Thuban                                  http://thuban.intevation.org/



More information about the Python-Dev mailing list