[Tutor] finally without try or except
Albert-Jan Roskam
fomcl at yahoo.com
Mon Jul 30 20:44:19 CEST 2012
From: Tino Dai <oberoc at gmail.com>
To: nz*tutor pythonzzz <tutor at python.org>
>Sent: Monday, July 30, 2012 6:56 PM
>Subject: [Tutor] finally without try or except
>
>
>Hi!
>
>
> Is there anyway to execute a block of code at the end of a program in 2.6 regardless of what happened before eg exiting normally or died because of an exception?
>I was thinking about maybe a free standing finally code block or a decorator.
>
>
>Any hints?
>Tino
>
>===> Hi, perhaps it's overkill, but you could define your own __exit__ (and __enter__) method so you can use a 'with' statement (context manager): http://docs.python.org/release/2.5.2/lib/typecontextmanager.html
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120730/a78d5141/attachment.html>
More information about the Tutor
mailing list