Michal Kwiatkowski <constant.b...@gmail.com> writes:

> I may be missing something obvious here. Is there a better way to tell
> if a given generator object is still active or not?

    foo = the_generator_object
    try:
        do_interesting_thing_that_needs(foo.next())
    except StopIteration:
        generator_is_exhausted()

In other words, don't LBYL, because it's EAFP. Whatever you need to do
that requires the next item from the generator, do that; you'll get a
specific exception if the generator is exhausted.

-- 
 \      “Courteous and efficient self-service.” —café, southern France |
  `\                                                                   |
_o__)                                                                  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to