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

Avoid using global/class-level mutable datatypes like list/dicts

Weakref proxy is for instance only ...