lambda generator - curious behavior in 2.5
James Stroud
jstroud at mbi.ucla.edu
Sat Apr 21 05:34:20 EDT 2007
Boris Borcic wrote:
> >>> x = (lambda : ((yield 666),(yield 777),(yield 888)))()
> >>> x.next()
> 666
> >>> x.next()
> 777
> >>> x.next()
> 888
> >>> x.next()
> (None, None, None)
> >>> x = (lambda : ((yield 666),(yield 777),(yield 888)) and None)()
> >>> x.next()
> 666
> >>> x.next()
> 777
> >>> x.next()
> 888
> >>> x.next()
>
> Traceback (most recent call last):
> File "<pyshell#29>", line 1, in <module>
> x.next()
> StopIteration
> >>>
Seems like a bug:
py> def doit():
((yield 1), (yield 2), (yield 3))
...
py> x = doit()
py> x.next()
1
py> x.next()
2
py> x.next()
3
py> x.next()
------------------------------------------------------------
Traceback (most recent call last):
File "<ipython console>", line 1, in <module>
<type 'exceptions.StopIteration'>
James
More information about the Python-list
mailing list