[Tutor] finally

Christopher King g.nius.ck at gmail.com
Sun Jun 27 01:45:40 CEST 2010


sorry, my reply to all button goofed up

On Sat, Jun 26, 2010 at 7:43 PM, Steven D'Aprano <steve at pearwood.info>wrote:

> Hi Christopher,
>
> Are you aware you have written directly to me instead of the tutor
> mailing list? It's normally considered rude to do so, unless your
> message truly is meant to be private.
>
>
> On Sun, 27 Jun 2010 09:24:22 am you wrote:
> > what about more complex cleanup code, like saving data or showing a
> > error message
> > how would the with statement coop with that
>
> Exactly the same as simple cleanup code. Just be careful not to rely on
> things which may not have happened inside the try block. E.g. this
> won't work:
>
> x = something()
> try:
>    y = x - 8
>    z = 100/y
> finally:
>    write_data_file(x, y, z)
>
> This will fail if something() returns 8, because z won't be defined, and
> your cleanup block itself will raise a NameError exception.
>
>
> --
> Steven D'Aprano
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100626/2dee6f74/attachment.html>


More information about the Tutor mailing list