[Python-Dev] Relative import
Greg Ewing
greg at cosc.canterbury.ac.nz
Wed Dec 17 18:24:12 EST 2003
> import P.Q (1)
> from P.Q import X (2)
>
> would only look for P in sys.path (I'll call this "absolute import");
> and
>
> from ...P.Q import X (3)
>
> would scan for P upwards from the current package.
>
> I think this addresses all the concerns I've seen brought up in this
> thread so far
No, it doesn't address my concern that scan-upwards semantics
should be the default, in the sense of being what should be
used in the absence of a reason to do otherwise, and should
therefore have the most straightforward syntax.
Also, you don't seem to have anything for the explicitly-relative
case, which might not be strictly necessary, but I think
I'd feel more comfortable if it were available somehow.
Thinking about the double_underscore names, it might not
be so bad if they were a bit shorter, e.g.
A: __root__.P.Q
B: __here__.P.Q
__here__.__parent__.P.Q
C: P.Q
Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
greg at cosc.canterbury.ac.nz +--------------------------------------+
More information about the Python-Dev
mailing list