Tk Dynamic Menus problem

Jeremy Bowers jerf at jerf.org
Wed Jul 24 20:11:38 EDT 2002


On Wed, 24 Jul 2002 13:42:22 -0500, Greg Krohn wrote:

> I'm not exactly sure why it's printing '3', but you do have a scoping
> problem there.
> Replace 'lambda: printFunc(i)' with 'lambda i=i: printFunc(i)'. Supplying i
> as a keyword arg for the lambda brings i into the labmda's scope.


Thanks, that did it.

I would be interested in a bit more explanation though. In the "real"
application, "i" were instances, not numbers (if that matters). Why would
the 'i' in the previously created lambda commands "shift" to follow the
outside value of i?

I thought I understood Python's scoping. ;-)



More information about the Python-list mailing list