Complete exception handling
try:
f = open(filename, 'r')
except IOError as e:
print 'cannot open ', filename
print "I/O error({0}): {1}".format(e.errno, e.strerror)
except:
log.exception("Unexpected error")
# print "Unexpected error:", sys.exc_info()[0]
raise
else:
print 'read', len(f.readlines()), 'lines'
finally:
print "executing finally clause"