[Python-ideas] Allow accessing return value inside finally clause
Steven D'Aprano
steve at pearwood.info
Wed Dec 26 00:02:24 CET 2012
On 26/12/12 08:46, Ram Rachum wrote:
> Say I have this function:
>
> def f():
> try:
> return whatever()
> finally:
> pass # I want to get what `whatever()` returned in here
>
> I want to get the return value from inside the `finally` clause.
>
> I understand that this is currently not possible. I'd like that to be
> possible because that would allow post-processing of a function's return
> value.
The usual ways to do that are:
def f():
return postprocess(whatever())
or:
def f():
return whatever()
x = postprocess(f())
Are these usual solution not suitable for your use-case?
--
Steven
More information about the Python-ideas
mailing list