[Python-ideas] with statement vs. try...except...finally (original) (raw)

Georg Brandl g.brandl at gmx.net
Wed Jun 3 09:11:36 CEST 2009


Nick Coghlan schrieb:

def getfirstline(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 = getfirstline('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



More information about the Python-ideas mailing list