Finally block always runs in python, avoid returning values in this block

>>> def foo():
...    try:
...        return 1
...    except:
...        return 2
...    finally:
...        return 3
... 
>>> foo()
3
>>> def foo():
...     try:
...        raise ValueError
...     except:
...        return 2
...     finally:
...        return 3
... 
>>> foo()
3

Comments

Popular posts from this blog

Multiple repeat error when the regex has multiple wildcards in python re module

Weakref proxy is for instance only ...

To speed up accessing files on nfs shares on a ubuntu machine ...