Distinguishing active generators from exhausted ones

Michal Kwiatkowski constant.beta at gmail.com
Mon Jul 27 17:37:57 EDT 2009


On Jul 27, 10:47 pm, Terry Reedy <tjre... at udel.edu> wrote:
> There are two possible definition of 'exhausted': 1) will raise
> StopIteration on the next next() call; 2) has raised StopIteration at
> least once. The wrapper converts 2) to 1), which is to say, it obeys
> definition 1 once the underlying iteration has obeyed definition 2.
>
> Since it is trivial to set 'exhausted=True' in the generator user code
> once StopIteration has been raised (meaning 2), I presume the OP wants
> the predictive meaning 1).

No, I meant the second meaning (i.e. generator is exhausted when it
has returned instead of yielding).

While, as you showed, it is trivial to create a generator that will
have the "exhausted" flag, in my specific case I have no control over
the user code. I have to use what the Python genobject API gives me
plus the context of the trace function.

Cheers,
mk



More information about the Python-list mailing list