The following program shows how to use nested scopes and lambda
pseudo-closures to do it:
wx.EVT_BUTTON( self.panel,
button.GetId( ),
(lambda index : lambda event self.OnClick( event, index ) ) (row)
)
···
--------------------------------------------------------
Although that is cool, any reason why you wouldn't use the following for the
callback, which only requires one lambda:
lambda event, row=row : self.OnClick( event, row )
Hi Steve,
Yes, that is an elegant further refinement. Capturing the bound value of the free variable at the time the function definition is executed (rather than when it is called later) is what's wanted, and using a default parameter to do that is a neat alternative. My double-lambda was soley due to the semantics of Python "closures" which provide a kind of indirection to the free variable in question, i.e. if we used:
lambda event : self.OnClick( event, row )
which is quite legal, we would get the current, i.e. last, value which "row" held, which is not what's wanted in the example.
···
In message <9DA07453A669D511AD1400508BA3991F034993FD@nyctaex001.na.webmd.net>, Zatz, Steve <szatz@webmd.net> writes:
The following program shows how to use nested scopes and lambda
pseudo-closures to do it:
wx.EVT_BUTTON( self.panel,
button.GetId( ),
(lambda index : lambda event self.OnClick( event, index ) ) (row)
)
--------------------------------------------------------
Although that is cool, any reason why you wouldn't use the following for the
callback, which only requires one lambda:
lambda event, row=row : self.OnClick( event, row )
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org
--
Pythonologist