Distinguishing active generators from exhausted ones
tjreedy at udel.edu
Mon Jul 27 08:02:19 CEST 2009
Steven D'Aprano wrote:
> On Sun, 26 Jul 2009 20:10:00 -0400, Terry Reedy wrote:
>> Michal Kwiatkowski wrote:
>>> The thing is I don't need the next item. I need to know if the
>>> generator has stopped without invoking it.
>> Write a one-ahead iterator class, which I have posted before, that sets
>> .exhausted to True when next fails.
> And hope that the generator doesn't have side-effects...
If run to exhastion, the same number of side-effects happen.
The only difference is that they each happen once step happpen sooner.
For reading a file that is irrelevant. Much else, and the iterator is
not just an iterator.
More information about the Python-list