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

Josiah Carlson jcarlson at nospam.uci.edu
Tue Mar 9 23:20:57 EST 2004


>>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



More information about the Python-list mailing list