本文摘自php中文网,作者黄舟,侵删。
本文实例讲述了Python中的错误和异常处理操作。分享给大家供大家参考,具体如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | print
try :
filename = raw_input ( "Enter file name:" )
output = open (filename, 'r' )
for eachline in output:
print eachline
output.close()
except IOError,e:
print "file open error:" ,e
|
运行结果:

以上就是Python中关于try-except用法的错误和异常处理详解的详细内容,更多文章请关注木庄网络博客!!
相关阅读 >>
Python中怎么查看内置函数
Python为什么安装了运行不了?
Python全栈工程师需要学什么
int是Python的保留字吗
自学Python有什么用
怎么用Python
Python中demo是什么
Python 读取图片文件为矩阵和保存矩阵为图片的方法
Python update函数定义及作用实例解析
Python中import有什么用法
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » Python中关于try-except用法的错误和异常处理详解