【发布时间】:2011-07-09 05:26:08
【问题描述】:
Why is else clause needed for try statement in python ?
继续前进:
try:
f = open('foo', 'r')
except IOError as e:
error_log.write('Unable to open foo : %s\n' % e)
else:
data = f.read()
f.close()
我突然想到else clause 解决的极端情况仍然可以通过nested try...except 避免,从而避免else 的需要? :
try:
f = open('foo', 'r')
try:
data = f.read()
f.close()
except:
pass
except IOError as e:
error_log.write('Unable to open foo : %s\n' % e)
【问题讨论】:
标签: python