[Tutor] finally without try or except

Tino Dai oberoc at gmail.com
Mon Jul 30 21:07:40 CEST 2012


On Mon, Jul 30, 2012 at 2:44 PM, Albert-Jan Roskam <fomcl at yahoo.com> wrote:

> *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
>
> That's actually I good idea, and will take a look at this because it will
expand my python knowledge. I'm not sure if I want to go down this path
because of the above stated reasons. -T
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120730/a6198a27/attachment-0001.html>


More information about the Tutor mailing list