newbie with major "lambda" problem (perhaps a scope problem as well)
Joe Potter
jm7potter at hotmail.com
Tue Jun 26 12:19:59 EDT 2001
On Tue, 26 Jun 2001 16:09:06 GMT, "Rainer Deyke" <root at rainerdeyke.com> wrote:
>"Joe Potter" <jm7potter at hotmail.com> wrote in message
>news:j5ahjtkfmf32lkqtap0q1u6rig385d7b5i at 4ax.com...
>> # the "button" below works like a champ !!
>> #Button(root, text='Fetch',
>> #command=(lambda v=vars: fetch(v))).pack(side=LEFT)
>>
>> # the "button" below does not do anything ??????
>> Button(root, text='Fetch', command=(fetch(vars))).pack(side=LEFT)
>
>Of course this doesn't work. It calls 'fetch(vars)', and passes the result
>to 'Button'. Use the lambda, that's what it's there for. Or use one of the
>'curry' alternatives (see archives).
My question is *why* the lambda is allowed to call the perfectly defined function
fetch, but a direct call of fetch is not.
In other words --- I already knew that I had to use lambda, but I do not know why!
In the 6 or 7 other languages I have used over time --- if you call a defined
function it works --- but in Python there is a mystery here.
Or, perhaps the mystery is deep down in Tkinter?
Regards, Joe
More information about the Python-list
mailing list