| Store | Cart

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

From: Stephen Horne <ste...@ninereeds.fsnet.co.uk>
Tue, 09 Mar 2004 01:09:19 +0000
On 8 Mar 2004 15:24:56 -0500, aahz at pythoncraft.com (Aahz) wrote:

>Here are the contenders:>>* One from Guido::>>      from .foo import>>  and ::>>      from ...foo 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)...

  [-----.dirname.dirname.dirname]filename

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

  [-5.dirname.dirname.dirname]filename

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

Recent Messages in this Thread
Aahz Mar 08, 2004 08:24 pm
John Roth Mar 09, 2004 01:04 am
Aahz Mar 10, 2004 10:49 am
John Roth Mar 10, 2004 01:04 pm
Stephen Horne Mar 10, 2004 04:44 pm
John Roth Mar 10, 2004 06:14 pm
Stephen Horne Mar 09, 2004 01:09 am
Mike Mar 09, 2004 03:39 am
Josiah Carlson Mar 09, 2004 06:34 am
Sean Ross Mar 09, 2004 06:13 pm
Paul Rubin Mar 09, 2004 10:44 pm
Josiah Carlson Mar 10, 2004 04:20 am
Andrew Clover Mar 10, 2004 01:18 pm
Sean Ross Mar 10, 2004 03:11 pm
Josiah Carlson Mar 12, 2004 07:06 am
Thomas Heller Mar 09, 2004 07:41 am
Andrew Clover Mar 09, 2004 10:12 am
Denis S. Otkidach Mar 09, 2004 10:50 am
Gerrit Mar 10, 2004 11:41 am
Anders J. Munch Mar 10, 2004 02:46 pm
Dieter Maurer Mar 11, 2004 10:29 pm
Geoff Howland Mar 14, 2004 12:50 am
Aahz Mar 10, 2004 11:01 am
John Roth Mar 10, 2004 01:13 pm
Messages in this thread