try/except/finally
Joshua Landau
joshua at landau.ws
Sun Jun 8 13:57:10 EDT 2014
On 8 June 2014 08:12, Marko Rauhamaa <marko at pacujo.net> wrote:
>
> Does anyone have an example motivating a return from finally? It seems
> to me it would always be a bad idea as it silently clears all unexpected
> exceptions.
In a general sense:
try:
something_that_can_break()
return foo() # before clean_up
finally:
clean_up()
if default:
return default() # after clean_up()
What's the best replacement? Note: I've never done this.
---
I do sometimes use
try:
return x
finally:
x += 1
over
ret = x
x += 1
return ret
now-a-days.
More information about the Python-list
mailing list