revive a generator

Yingjie Lan lanyjie at yahoo.com
Thu Oct 20 22:09:42 EDT 2011


> Here's an example of an explicit request to revive the generator:

> 
>>>>  g = (x*x for x in range(3))
>>>>  for x in g: print x
> 0
> 1
> 4
>>>>  g = (x*x for x in range(3)) # revive the generator
>>>>  for x in g: print x #now this will work
> 0
> 1
> 4
> 
> ChrisA


What if the generator is passed in as an argument 
when you are writing a function? That is, the expression
is not available? 

Secondly, it would be nice to automatically revive it.
For example, when another for-statement or other
equivalent is applied to it.

Yingjie



More information about the Python-list mailing list