importing symbols from module objects

Peter Hansen peter at engcorp.com
Wed Sep 26 23:13:21 EDT 2001


Markus Schaber wrote:
> 
> 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.

I guess it just produces similar final results, without
precisely those intermediate steps.  Sorry to confuse.

-- 
----------------------
Peter Hansen, P.Eng.
peter at engcorp.com



More information about the Python-list mailing list