
June 3, 2009
9:11 a.m.
Nick Coghlan schrieb:
def get_first_line(fname): try: f = open('foo') except IOError: line = "can't open" try: line = f.readline() except IOError: line = "can't read" try: f.close() except IOError: line = "can't close" return line
line = get_first_line('foo')
Anyway, doesn't it make more sense to report not what *operation* failed, but what the *failure* was (the specifics of the IOError)? Georg