Singleton generators as code blocks
Greg Ewing (using news.cis.dfn.de)
g2h5dqi002 at sneakemail.com
Mon Nov 24 00:41:37 EST 2003
Jp Calderone wrote:
> This is a pretty nifty approach, but it seems to have (at least?) one serious
> drawback. If the body of the loop raises an exception, the generator is
> never resume, and the cleanup (or whatever) is never run.
If open_file were implemented as a class rather than a
generator, maybe the cleanup could be implemented with its
__del__ method.
Or maybe the iterator protocol should include a __cleanup__
or __finally__ method that the for-loop invokes before leaving
via a break or exception?
--
Greg Ewing, Computer Science Dept,
University of Canterbury,
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg
More information about the Python-list
mailing list