How many times inner functions are compiled ?
Just van Rossum
just at letterror.com
Tue Jun 13 09:34:10 EDT 2000
At 2:16 PM +0200 13-06-2000, Thomas Wouters wrote:
>On Tue, Jun 13, 2000 at 02:01:20PM +0200, Jerome Quelin wrote:
>
>> def outer():
>> def inner():
>> print "spam"
>> inner()
>> outer()
>> outer()
>
>> In the snippet code above, I call outer() two times. I would like to
>> know how many times python will compile the inner function ? One time
>> when compiling the script/module, or two times, ie at every invocation
>>of the
>> outer function ?
>
>Once for every invocation of outer().
Not true: compilation happens at compile time (duh!) which is only during
the first import and only if there's no .pyc file yet. A new function
object for inner() will be created at each invocation of outer(), but the
_code_ object for that function will be the same.
Just
More information about the Python-list
mailing list