I really don't understand Lambda!
Bob van der Poel
bvdpoel at kootenay.com
Mon Oct 14 14:22:31 EDT 2002
Ian Bicking wrote:
>
> On Thu, 2002-10-10 at 18:49, Bob van der Poel wrote:
> > 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) )
>
> I think you want:
>
> wg.bind("<Return>", lambda e, s=wg: seq.setSize(s))
>
> The callback is always called with the event as the one argument (even
> if you don't care about the event).
>
> Ian
Thanks. This works perfectly.
Understanding a bit more... Am I correct in understanding that the args
(if that is what they are called) between the 'lambda' and the ':' are
evaluated when the bind is first evaluated.... So, if 'wg' is changed
later the 's' is in it's own namespace and not affected.
--
Bob van der Poel ** Wynndel, British Columbia, CANADA **
EMAIL: bvdpoel at kootenay.com
WWW: http://www.kootenay.com/~bvdpoel
More information about the Python-list
mailing list