[Python-Dev] Relative import

Ken Manheimer klm at zope.com
Wed Dec 17 18:57:23 EST 2003

On Thu, 18 Dec 2003, Greg Ewing wrote:

> 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

Why separate __here__ and __parent__?  (I may just be confused, here.)
Aren't both about getting the relative package container?  Discussing
schemes for explicit relative and absolute imports with some
colleagues a few days ago, we liked '__pkg__' for the package
containing the current module - and __pkg__.__pkg__ to mean its'
container (and so on, for those non-programmers out there:-).  Someone
also wanted explicit expression of absolute, which we thought might be

A: __python__.P.Q
B: __pkg__.P.Q
C: P.Q

That said, *i* much prefer the leading '.' scheme - i think the
underscores are distinctly *not* easier to read, and i'm not bothered,
anyway, by the "punctuality" of the leading-'.' - i think it stands
out enough to be noticable, and the fractured-path implication of it
conveys the relativeness...

klm at zope.com

More information about the Python-Dev mailing list