import x as y

Delaney, Timothy tdelaney at avaya.com
Mon Oct 30 01:26:06 EST 2000


> > Just wondering, as a python 'advanced' novice, is there any 
> advantage
> > of:
> > 
> > import x as y
> > 
> > ratheer than
> > 
> > import x
> > y=x
> > ?
> > 
> > Or is it just the elimination of the extra line?
> 
> And the namespace polution: the "as" version doesn't create a variable
> named x.
> The "as" version is equivalent to
> 
> import x;y=x;del x
> 
> It happened so much, it has been decided to make it a one-liner.

Further to this ...

import x
y = x
del x

*does* pollute the local namespace for a short while (if you already have x
in the local namespace it will get rebound to the module). Does

import x as y

still pollute for that period of time, or is x *never* in the local
namespace? And if you have an x before you import, will that x still be
bound to whatever it was?

Tim Delaney
Avaya Australia




More information about the Python-list mailing list