Speed of Nested Functions & Lambda Expressions
beginner
zyzhu2000 at gmail.com
Tue Oct 23 11:40:50 EDT 2007
Hi All,
It is really convenient to use nested functions and lambda
expressions. What I'd like to know is if Python compiles fn_inner()
only once and change the binding of v every time fn_outer() is called
or if Python compile and generate a new function object every time. If
it is the latter, will there be a huge performance hit? Would someone
give some hint about how exactly Python does this internally?
def fn_outer(v):
a=v*2
def fn_inner():
print "V:%d,%d" % (v,a)
fn_inner()
Thanks,
Geoffrey
More information about the Python-list
mailing list