Not understanding absolute_import

Peter Otten __peter__ at
Sun Apr 8 08:37:50 CEST 2007

Nate Finch wrote:

> On Apr 5, 8:33 am, "Nate Finch" < at> wrote:
>> I've been trying to use fromabsolute_importand it's giving me a hell
>> of a headache.  I can't figure out what it's *supposed* to do, or
>> maybe rather, it doesn't seem to be doing what I *think* it's supposed
>> to be doing.
> No one?  Is this too simple a question, or is it just that no one is
> using this?

The latter, I suppose.

The PEP has the following example:


Assuming that the current file is either or
subpackage1/, following are correct usages of the new syntax:

from .moduleY import spam
from .moduleY import spam as ham
from . import moduleY
from ..subpackage1 import moduleY
from ..subpackage2.moduleZ import eggs
from ..moduleA import foo
from ...package import bar
from ...sys import path

I tried that and it turned out that you have to change

from ...package import bar
from ...sys import path


from ..package import bar
from ..sys import path

for the code to run without raising an exception. I therefore assume that
the current implementation erroneously mixes the top level and its
immediate child level, and I suggest that you file a bug report.


More information about the Python-list mailing list