"helper function" style question
Terry Reedy
tjreedy at udel.edu
Tue Jul 13 14:21:54 EDT 2004
"Paul Morrow" <pm_mon at yahoo.com> wrote in message
news:ccv6ck$blt$1 at sea.gmane.org...
> slower than the first (I can imagine that the byte compiler could be
> smart enough not to recompile or rebind hf on each invocation of m1), in
>From years ago comments by those in the know, the body of inner function is
compiled just once, as for outer functions, and saved in a code object, but
the function object is recreated each time the def statement is executed.
Rebinding is necessary; so it either recreating the function object or at
least patching a cached version . Consider the following skeleton:
def outer(a, b):
if a:
def inner(x, y=b): pass
else:
def inner(x, y=[b]): pass
return inner
Terry J. Reedy
More information about the Python-list
mailing list