revive a generator
Dave Angel
d at davea.name
Fri Oct 21 07:11:49 EDT 2011
On 10/20/2011 10:09 PM, Yingjie Lan wrote:
> <snip>
>
> 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
That last point would definitely be incompatible. It's quite useful to
be able to peel some values off a generator, then use a for loop to get
the remainder. Simplest example I can think of would be to read a file
where the first line(s) represent header information, and the body is
obtainable with a simple loop. I wouldn't be surprised if the csv
module does that.
Not arguing whether an explicit revival is useful or not. Although as
others have pointed out, not all generators could accomplish it, and in
some cases not unambiguously.
--
DaveA
More information about the Python-list
mailing list