python异常处理
来源:互联网 发布:守望先锋性能数据 ping 编辑:程序博客网 时间:2024/06/13 00:31
1、捕获,处理异常
try:
a = 1/0
b = test
except AttributeError as e:
print str(e)
except ZerovisitionError as e:
print str(e)
finally:
print 111
2、抛异常:
raise AttributeError('属性不存在')
3、with替代文件操作频繁的开、关
一般麻烦情况:
with情况不需要关闭,他自己会帮你关闭
try:
a = 1/0
b = test
except AttributeError as e:
print str(e)
except ZerovisitionError as e:
print str(e)
finally:
print 111
2、抛异常:
raise AttributeError('属性不存在')
3、with替代文件操作频繁的开、关
一般麻烦情况:
try:
f = open('aa.txt','w')
test = f.read()
except IOError as e:
print('io:',e)
finally:
print('close')
f.close()
with情况不需要关闭,他自己会帮你关闭
try:
with open('bb.txt','w') as f:
test = f.read()
except IOError as e:
print(e)
阅读全文
0 0
- Python异常和异常处理
- python异常处理
- Python异常处理
- python 异常处理
- python异常处理
- python如何处理异常
- python之异常处理
- python异常处理
- python异常处理
- Python异常处理
- python异常处理
- python的异常处理
- python的异常处理
- python 异常处理
- python 异常处理
- python 异常处理
- Python异常处理
- Python异常处理
- 设计模式之命令模式的学习思考
- 【剑指Offer】面试题10:二进制中1的个数
- 一个PDF合并操作实现类,利用iTextSharp控件实现
- 获取List集合泛型参数
- Android App优化之性能分析工具
- python异常处理
- 因为爬虫,我的老板进监狱了——真是搞扯!
- 通过adb命令从手机中复制文件到PC端
- 下拉框
- python面向对象问题
- 内核同步介绍
- 【bzoj3791】作业
- db2 SQL0668N 原因码7问题解决
- 股票K线统计,各个分钟线,日线,周线统计,sql示例