[New-bugs-announce] [issue22761] Catching StopIteraion inside list comprehension
yotamv
report at bugs.python.org
Wed Oct 29 22:19:01 CET 2014
New submission from yotamv:
Inside a list comprehension expression, if a StopIteration exception is raised, the interpreter assumes the exception was raised by the object Iterated buy the list comprehension expression.
For example, this generator will never stop, and will keep returning empty tuples:
def izip(*args):
iters = [iter(obj) for obj in args]
while True:
yield tuple(next(it) for it in iters)
x = izip([1,2],[3,4])
print(next(x)) #(1,3)
print(next(x)) #(2,4)
print(next(x)) #()
----------
components: Interpreter Core
messages: 230246
nosy: tomirendo
priority: normal
severity: normal
status: open
title: Catching StopIteraion inside list comprehension
type: behavior
versions: Python 3.4
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22761>
_______________________________________
More information about the New-bugs-announce
mailing list