Makeing a constant ??

Nathan Froyd froydnj at rose-hulman.edu
Fri Mar 17 08:54:39 EST 2000


Matthias Barmeier wrote:
>This expression looks like this:
>	widget.bind(itemName, lambda e, cb=self.driveEvent: 
>			cb(e,itemName))
>
>The second itemName in this expression is my problem.
>When the event is fired I always get the message that itemName is
>unknown.

It's not so much that you need a "constant" variable (I have no idea what
you're taking about here), but that the lambda expression can't see
`itemName'. I believe this question is answered in the FAQ, but since I had
problems with it, here's code that should work:

widget.bind(itemName, lambda e, cb=sel.driveEven, itemName=itemName:
			cb(e,itemName))
			
That should do what you want.
-- 
</nathan><sig>froydnj at rose-hulman.edu  |  http://www.rose-hulman.edu/~froydnj/

...you could spend *all day* customizing the title bar. Believe me. I speak
from experience. --Matt Welsh                                           </sig>



More information about the Python-list mailing list