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

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


Diez B. Roggisch wrote:
>>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?
> 
> 
> Strange. This script works and shows the desired behaviour - python is also
> 2.3.4:
> 
> def foo(x):
>     print x
> 
> 
> fs = [lambda: foo(i) for i in xrange(5)]
> for f in fs:
>     f()
> 
> fs = [lambda x=i: foo(x) for i in xrange(5)]
> for f in fs:
>     f()
> 
> 
You're right! It was my fault. I left the colon after the lambda by 
mistake. e.g. lambda: num=verseNum:...

Thanks very much for the help it works great now! I wish I would have 
asked somebody sooner :)
-Matthew



More information about the Python-list mailing list