[Python-Dev] PEP 343 - Abstract Block Redux

Delaney, Timothy C (Timothy) tdelaney at avaya.com
Mon May 16 07:59:41 CEST 2005


Steven Bethard wrote:

> If I've misunderstood, and there are other situations when
> "needs_finish" is required, it'd be nice to see some more examples.

The other cases are where you want to do something in response to an
exception, but not otherwise::

    def gen():
        try:
            yield
        except:
            print 'Got exception:', sys.exc_info()
            raise

Personally, I think they're rare enough that you could use a decorator
in those cases, but still have::

    def gen():
        try:
            yield
        finally:
            pass

automatically make the generator conform to the do/with protocol.

Tim Delaney


More information about the Python-Dev mailing list