PEP 328: Imports: Multi-Line and Absolute/Relative

Stephen Horne steve at
Tue Mar 9 02:09:19 CET 2004

On 8 Mar 2004 15:24:56 -0500, aahz at (Aahz) wrote:

>Here are the contenders:
>* One from Guido::
>      from .foo import
>  and ::
>      from import
>  These two forms have a couple of different suggested semantics.  One
>  semantic is to make each dot represent one level.  There have been
>  many complaints about the difficulty of counting dots.  Another
>  option is to only allow one level of relative import.  That misses a
>  lot of functionality, and people still complained about missing the
>  dot in the one-dot form.  The final option is to define an algorithm
>  for finding relative modules and packages; the objection here is
>  "Explicit is better than implicit".  (The algorithm proposed is
>  "search up from current package directory until the ultimate package
>  parent gets hit".)

My thoughts are that (1) if dots aren't obvious enough, use something
more obvious; and (2) if you don't want to count things, write the
number directly.

I'd suggest taking a tip from VMS path syntax. A VMS relative pathname
typically looks a bit like this (I appologise if this is slightly
wrong - it has been a long time)...


This, of course, just replaces counting dots with counting hyphens.
But what about...


Obviously mapping it to the importing context, that means putting the
location of the module to import in square brackets, using dots as
separators, and allowing negative integers (or a single hyphen) for
stepping outward.

For small numbers of outward steps, just repeating the hyphen may work
better so maybe that should be an option too.

I'm not so sure about the square brackets myself, but using hyphens
and/or negative integers for stepping outward seems like quite a clear
and obvious way to do it. Unless I'm making some stupid mistake, that
is - I confess that I've never used packages myself.

Steve Horne

steve at ninereeds dot fsnet dot co dot uk

More information about the Python-list mailing list