| Store | Cart

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

From: Josiah Carlson <jcar...@nospam.uci.edu>
Tue, 09 Mar 2004 20:20:57 -0800
>>from MODULE import NAMES as RENAME searching HOW>>import NAMES as RENAME from MODULE searching HOW> > I like this.

Great.  On the other hand, import has been changed radically, and the 
only sign is the additional 'from' keyword.

>>Or for backwards compatibility:>>from HOW.MODULE import NAMES as RENAME>>import HOW.MODULE.NAMES as RENAME> > I don't see any need for this.  Backwards compatibility doesn't> require adding new stuff.  Just leave those forms the way they were.

It isn't adding new stuff.  Currently, imports are handled like so:
from PACKAGE1.PACKAGE2.MODULE import NAMES as RENAME
from PACKAGE1.PACKAGE2 import MODULE as RENAME

The only difference is that HOW is either the classic 
PACKAGE1.PACKAGE2.(etc) or the new -<INTEGER>.PACKAGE1.(etc)

The trick is that all old import statements will still work, but one can 
use old-style (familliar) syntax and still gain the use of relative imports.


> Ugh!  What's wrong with ../sibling_package or> ../../uncle_package/cousin_package instead of the -1,-2 stuff?

You should remember that what I gave was a suggestion.  Personally, I 
don't like ../../../(etc) because I am:
1. lazy
2. sick of seeing paths in language include/import statements
3. happy to re-use the currently used idea of namespaces and '.' notation

> I think it's ok to use slashes.

In reality, it is not ok to use slashes.  If you pay attention to the 
posts here, you'll notice the incidence of unescaped backslashes from 
users on Windows.  In such a case, we would have 3 options:
1. Disable backslash escaping on during imports (removing the 
consistancy of backslash escaping everywhere else).
2. Leave in backslash escaping (requiring double backslashes for all 
relative imports, and wait for the posts to c.l.py about why relative 
imports don't work on Windows).
3. Only allow forward slashes.

I think all three options suck ass, which is why I extended Stephen's 
posted VMS-like syntax, which makes stepping up one or five additional 
or fewer levels arbitrarily easy.  I know I would prefer to change a 
number than to include a series of additional ../.

  - Josiah

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
Andrew Clover Mar 15, 2004 09:52 am
Bernhard Herzog Mar 15, 2004 11:26 am
Aahz Mar 10, 2004 11:01 am
John Roth Mar 10, 2004 01:13 pm
Messages in this thread