Execution of import (was Re: boolean xor)
Peter Hansen
peter at engcorp.com
Mon Jan 8 07:05:50 EST 2001
Tim Peters wrote:
>
> > def xor(a,b):
> > from operator import truth
> > return truth(a) ^ truth(b)
>
> [Peter Hansen]
> > An aside: does the 'from .. import' statement execute every time
> > the function 'xor' is called, or only during the execution
> > of the 'def' statement?
>
> Imports of X after the first are just lookups, mapping the
> module name to the (already executed) module object and retrieving the
> latter.
Despite the timing thread that follows your response, your
answer is all I needed. <wink> Temporary brain fart made me
incapable of picturing that 'truth' was not rebound
dynamically every time through the function (and therefore
that _of course_ import must executed each time through).
I guess all that talk about Java and C recently switched
my brain back to a less dynamic mode. Thanks. :)
More information about the Python-list
mailing list