[Tutor] How to pass multiple variables in callback function?
kent37 at tds.net
Wed Dec 6 04:21:42 CET 2006
Alan Gauld wrote:
> "Asrarahmed Kadri" <ajkadri at googlemail.com> wrote
>> I mean to say that suppose I have two lists, and I want to pass them
>> to the
>> event handling function. Is that possible using bind?
> Not answering your question directly but you can do
> it with a lambda expression.
> def myfunc(l1,l2):
> # the func I want to use
> foo = lambda p1=list1, p2=list2: myfunc(p1,p2)
> or just
> bind(e,lambda p1=list1, p2=list2: myfunc(p1,p2))
> Obviously(?) list1 and list2 need to be in the same scope as
> the lambda expression!
Unless the bind() is in a loop that is rebinding list1 and list2, the
named parameters are not needed since nested scopes were introduced in
Python 2.1, you can just write
bind(e,lambda: myfunc(list1, list2))
More information about the Tutor