The try ... except statement has an optional else clause, which, when present, must follow all except clauses. It is useful for code that must be executed if the try clause does not raise an exception. For example:
- for arg in sys.argv[1:]:
- f = open(arg, 'r')
- except IOError:
- print 'cannot open', arg
- print arg, 'has', len(f.readlines()), 'lines'
You need to login to post a comment.