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

Splitting python path using os.path module

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

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