遗憾的是,我不知道如何处理python"with"语句的异常.如果我有密码:
with open("a.txt") as f:
print f.readlines()
我真的很想处理‘文件未找到异常’,以便做一些事情.但是我不会写
with open("a.txt") as f:
print f.readlines()
except:
print 'oops'
而且不会写字
with open("a.txt") as f:
print f.readlines()
else:
print 'oops'
将"with"括在try/Except语句中不起作用,否则不会引发异常.我能做些什么才能以Pythonic的方式处理‘With’语句中的失败呢?