File: class/Workbook/Examples/Lecture8/finally.py

def divide(x, y):
    return x / y          # divide-by-zero error?

def tester(y):
    try:
        print divide(8, y)
    finally:
        print 'on the way out...'

print '\nTest 1:'; tester(2)
print '\nTest 2:'; tester(0)     # trigger error



[Home page] Books Code Blog Python Author Train Find ©M.Lutz