I really don't understand Lambda!
Bob van der Poel
bvdpoel at kootenay.com
Fri Oct 11 01:49:04 CEST 2002
Just when I thought I was understanding lambda, it totally confuses me.
I have the following statement in my program, which works:
wg.bind("<Return>", lambda s=wg: seq.setSize(wg) )
In this case 'wg' is a tkinter Entry widget and seq.setSize is a class
method which extracts some data from the widget, etc. So far, so good.
However, originally, I had tried:
wg.bind("<Return>", lambda s=wg: seq.setSize(s) )
And this doesn't work. Instead of passing a reference to the Entry, it
passes the event. Clearly not what I wanted.
So, if we don't need to use the variable, why not leave out the
wg.bind("<Return>", lambda : seq.setSize(wg) )
Nope, seems we have to have some kind of arg, dummy or otherwise.
So, (1) do we always need some kind of assignment between the 'lambda'
and the ':'?
And (2) why doesn't my assignment attempt work?
Bob van der Poel ** Wynndel, British Columbia, CANADA **
EMAIL: bvdpoel at kootenay.com
More information about the Python-list