Benjamin Kaplan wrote:

I don't know if anyone considers python's incomplete implementation of
closures a "feature" but it's documented so it's not really a bug
either.

I believe Python's implementation of closures is quite complete in 3.x. In what way do you consider it otherwise? One just has to use the right syntax. Closures in Python are created by nested function definitions. Lambda expressions create functions just like def statements and are not closures and do not create closure unless nested within another function definition. Thinking otherwise is the OP's mistake.

I believe there is a trick with default arguments to get this
to work, but I don't use lambdas enough to remember it.

One can simulate closures by giving an un-nested function a default argument. This has nothing to do with whether the function is defined by a lambda expression or a def statement.

Terry Jan Reedy


--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to