You can duplicate code to avoid the finally block:
try: yield 42 finally: do_something()
becomes:
try: yield 42 except:
(I have not tried this on Python 2.4, you may have to look for sys.exc_info instead of re-raise above, as in raise sys.exc_info[0], sys.exc_info[1], sys.exc_info[2] .)
Roger Pate
source share