Lambdas and variables
derek.thomson at gmail.com
Wed Jul 28 02:03:30 CEST 2004
On 27 Jul 2004 16:35:39 -0700, John Fouhy <jfouhy at paradise.net.nz> wrote:
> So I'm trying to generate Tkinter callback functions on the fly, but
> it's not working, and I don't understand what's going on.
> [snip examples]
> Can anyone explain this to me?
I'll have a go.
It's to do with the environment to which a function, or a lambda, is
bound. "x" in the lambda will always refer to the x defined in the
enclosing scope, and you last left that set to "zof".
The next case with an explicit function makes it all better because
now the printSomething function has a reference to the actual element
you wish to use via it's argument.
Hope that helps!
More information about the Python-list