Nested generator caveat

marek.rocki at wp.pl marek.rocki at wp.pl
Mon Jul 7 08:06:04 CEST 2008


Excellent explanation by Mark Wooding. I would only like to add that
the standard pythonic idiom in such cases seems to be the (ab)use of a
default argument to the function, because these get evaluated at the
definition time:
def gen0():
	for i in range(3):
		def gen1(i = i):
			yield i
		yield i, gen1()



More information about the Python-list mailing list