[Python-Dev] 'import as'

Gordon McMillan gmcm@hypernet.com
Fri, 18 Aug 2000 10:42:20 -0400


Barry "5 String" Warsaw wrote:

> But I think it /is/ useful behavior for "import <dotted name> as"
> to bind the rightmost attribute to the local name. 

That is certainly what I would expect (and thus the confusion 
created by my original post).

> I agree
> though that if that can't be done in a sane way, it has to raise
> an exception. But that will frustrate users.

"as" is minorly useful in dealing with name clashes between 
packages, and with reallyreallylongmodulename.

Unfortunately, it's also yet another way of screwing up circular 
imports and reloads, (unless you go whole hog, and use Jim 
Fulton's idea of an assoctiation object).

Then there's all the things that can go wrong with relative 
imports (loading the same module twice; masking anything 
outside the package with the same name).

It's not surprising that most import problems posted to c.l.py 
get more wrong answers than right. Unfortunately, there's no 
way to fix it in a backwards compatible way.

So I'm -0: it just adds complexity to an already overly complex 
area.

- Gordon