Dynamic methods and lambda functions
Michael Torrie
torriem at gmail.com
Sat Jan 24 16:23:10 EST 2009
unineuro at gmail.com wrote:
> The attributes are right, but the getter are not working. The problem
> is that the lambda function always execute the last parameter passed
> for all instances of the methods. How could it be done the right way?
Basically, don't use a lambda. Create a real, local closure with a
nested def block. That way the closure is created every time the parent
function is called. Lambda expressions are only ever compiled once
during execution.
More information about the Python-list
mailing list