[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
- Previous message: [Python-ideas] with statement vs. try...except...finally
- Next message: [Python-ideas] with statement vs. try...except...finally
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message: [Python-ideas] with statement vs. try...except...finally
- Next message: [Python-ideas] with statement vs. try...except...finally
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]