[Chicago] import question

Chris McAvoy chris.mcavoy at gmail.com
Wed Jan 23 03:29:46 CET 2008


On Jan 22, 2008 4:55 PM, Massimo Di Pierro <mdipierro at cs.depaul.edu> wrote:
> This does not solve the problem

It's possible that this is a problem that Python specifically doesn't
solve?  I really don't know for sure, but given the way Python loves
namespaces, I'd assume that they're sacred enough to maybe not allow
you to do something like this.

I don't know for sure, but from a "Zen of Python" perspective, when I
can't do something with Python it usually ends up that what I'm trying
to do shouldn't be done.

If I'm wrong, I'm wrong, I'm just thinking this might fall into that category.

Reading that relative import PEP, this looks like what you want...just
in 2.5 (which a gajillion people have pointed out, I'm just pasting
the exact part):

"""Additional leading periods perform the relative import starting
from the parent of the current package. For example, code in the A.B.C
module can do:

from . import D                 # Imports A.B.D
from .. import E                # Imports A.E
from ..F import G               # Imports A.F.G"""

You just have to know how deep you are, so if your 'contrib' module
ends up being multiple deep, you're screwed.  Which I think is what
you were saying when you didn't want to edit the test.__init__.py.

Anywho, it might just not be solvable.


More information about the Chicago mailing list