help with relative imports

richard.charts at gmail.com richard.charts at gmail.com
Tue Sep 19 20:57:09 CEST 2006


John Salerno wrote:
> Robert Kern wrote:
>
> > What is ambiguous about A.B.D, A.E, and A.F.G? But if you like:
>
> I guess maybe I was looking at it backwards. From the way it was worded,
> I thought the only information we had to use was the structure A.B.C,
> and then given a statement like:
>
> from . import D
>
> we just had to figure out for ourselves that this results in A.B.D,
> instead of, for example, A.C.D, or any other possibility.
>
> But I'm still a little confused about the use of the single or double
> period. In this case:
>
> from . import D                 # Imports A.B.D
> from .. import E                # Imports A.E
>
> why do you need a single period in the first example, and a double in
> the second, if they both are importing from A? If E is directly under A,
> couldn't you just use a single period? And since D is nested twice
> beneath A (i.e., in A, then in B), wouldn't you need two periods there
> instead?

I was staring at this too for a bit.
You just have to remember basic directory relative paths:
. -> Current Directory
.. -> One level up from current.

At least I'm assuming this is right based on the test and the example
above.




More information about the Python-list mailing list