problem with tk and pass by refference (I think :)

Matthew Thorley ruach at chpc.utah.edu
Fri Feb 11 15:14:27 EST 2005


Diez B. Roggisch wrote:
> Hi,
> 
> button = Button(self.songWin, text=verse, command=(lambda num=verseNum:
> self.showVerse(num)) )
> 
> should do the trick. The reason is basically that your version kept a
> reference to verseNum - and when executed, the value verseNum points to is
> the lasts one stored.
> 
> Rebinding the argument to a parameter in the lambda will keep the right
> value for each iteration.
> 
> 
I tried it but I got a syntax error. The interpreter didn't like the 
equals sign in the lambda. I am using python 2.3.4. Is there another way 
of writing that?

thanks



More information about the Python-list mailing list