[Python-Dev] PEP 328 - Relative Imports

Shane Holloway (IEEE) shane.holloway at ieee.org
Sat Sep 11 08:25:38 CEST 2004

M.-A. Lemburg wrote:
> People are more likely going to make all imports absolute (like
> they already do in Java and other languages) - which
> is good, since it makes reading code much easier and allows for
> writing packages which are compatible to older Python version,
> but it also prevent developing applications using the above
> approach.
> I also don't think that extension writers will care enough to
> make their packages fully relocateable by using relative
> imports all over - these are hard to read and don't buy
> the developer of the extension anything.
> Anyway, what should the strategy for the PEP look like ?
> 1. postpone the defaulting to absolute until P3k
> 2. provide a way to customize the behaviour using
>    e.g. a sys function

As a package writer, I will go through the effort to write relative 
imports for a few reasons.

  * One is that I often don't know what the final layout of the larger 
package group will be; however, I am usually fairly certain about local 
dependencies.  Having a way to refer to a parent package will enable me 
to be "complete" in this development style.

  * Second, it's really handy to develop something in the sandbox, and 
then move it to production in one fell swooop.  BTW, will __path__ work 
for relative parent references?

  * A third reason I will go through the effort to use relative imports 
is that I'd like to allow application frameworks (and other package 
writers) to "scoop up" any whole packages if they so desire.

Unfortunately, it'll be a while before I can target Python 2.4 directly. 
  But it will be good when I can!

-Shane Holloway

More information about the Python-Dev mailing list