[Python-Dev] Relative vs. absolute imports

Bernhard Herzog bh at intevation.de
Wed May 19 15:34:49 EDT 2004


"Phillip J. Eby" <pje at telecommunity.com> writes:

> Yes it is, actually.  You can answer the "print foo" question simply by
> inspecting the code of the function that contains it.  (And if it's not
> in a function, you know it's a global, unless it's never assigned, in
> which case it's a builtin.)
>
> But the "import foo" question cannot be answered by referring to the
> source of the module in which it occurs.

Of course it's different, but it's not all that much different.  To
determine whether an import is relative or not you look into the
directory containing the module with the import statement.  Shouldn't be
more than a few keystrokes in a decent editor.

> IIRC, nobody has suggested eliminating them prior to 3.0, which will
> have lots of other backward-incompatible changes anyway.

The new import scheme will be the only one available in Python 2.6 and
later according to the PEP and the current style of relative imports
will produce DeprecationWarnings in 2.5.

   Bernhard

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



More information about the Python-Dev mailing list