importing symbols from module objects

Markus Schaber markus at schabi.de
Wed Sep 26 11:53:54 EDT 2001


Hi,

Peter Hansen <peter at engcorp.com> schrub:

>> Hey, that ought to work.  I'm the one that missed something.  I'm not
>> totally used to this exceptions=classes=instances stuff yet.  Now I
>> have to wonder what "from foo import bar as parrot" really does.
>> Maybe pretty much the same thing.  Anyway, thanks, I'll give it a
>> try.
> 
> It does this:
> 
> from foo import bar
> parrot = bar
> del bar

Is this really true?

With a.py containing:

def f():
  print "hello"

I did the following in python 2.0.1 interactive mode:
>>> a = 1
>>> f = 2
>>> from a import f as x
>>> print a,f,x
1 2 <function f at 0x805c384>

Given your definition, f would be overwritten with the function and 
then deleted, thus not be bound to 2 any more.

markus
-- 
"The strength of the Constitution lies entirely in the determination of 
each citizen to defend it. Only if every single citizen feels duty 
bound to do his share in this defense are the constitutional rights 
secure." -- Albert Einstein



More information about the Python-list mailing list