Frank B <fbick...@gmail.com> Wrote in message:
> Ok; this is a bit esoteric.
> So finally is executed regardless of whether an exception occurs, so states
> the docs.
> But, I thought, if I <return> from my function first, that should take
> au contraire
> Turns out that if you do this:
> except FailException:
> return 0
> return 1
> Then finally really is executed regardless... even though you told it to
> That seems odd to me.
The thing that's odd to me is that a return is permissible inside
a finally block. That return
should be at top level, even with the finally line. And of course
something else should be in the body of the finally
If you wanted the finally block to change the return value, it
should do it via a variable.
retval = 0
I imagine the finally clause was designed to do cleanup, like
closing files. And it certainly predated the with statement.