Python Exception
来源:互联网 发布:cyberduck mac 编辑:程序博客网 时间:2024/05/22 03:15
1 异常的处理
#!/usr/bin/python3
# exceptions.py by Bill Weinman [http://bw.org/]# This is an exercise file from Python 3 Essential Training on lynda.com
# Copyright 2010 The BearHeart Gorup, LLC
def main():
try:
fh = open('sslines.txt') #当文件不存在时
except IOError as e:
print("Could not open the file.come back tommorow",e)
else:
for line in fh: print(line.strip())
if __name__ == "__main__": main()
2 抛出异常
#!/usr/bin/python3
# exceptions.py by Bill Weinman [http://bw.org/]
# This is an exercise file from Python 3 Essential Training on lynda.com
# Copyright 2010 The BearHeart Gorup, LLC
def main():
try:
for line in readFile("han.doc"):
print(line.strip())
except IOError: print('file does not exist')
except ValueError as e:print(e)
def readFile(filename):
if filename.endswith('.txt'):
fh=open(filename)
return fh.readlines()
else:
raise ValueError('File name must end with .txt')
if __name__ == "__main__": main()
0 0
- Python Exception
- Python Exception
- python exception
- Python Exception
- python exception
- python exception
- Python exception
- python的异常Exception
- Python Exception Name
- python学习exception
- python Exception 异常处理
- Python,异常 exception
- python re-raise exception
- Python中的try... exception
- python 获取exception 名字
- Python Built-in Exception
- Python 异常(Exception)
- python——exception
- AssetManager asset的使用
- Java中的instanceof关键字
- 多个应用相互传值
- Java之关闭流
- ios 画图函数
- Python Exception
- NPOI 创建Excel,数据读取与写入
- Android读取不同位置(drawable,asset,SDCard)的图片资源
- php类中 self parent static的区别
- leetcode ZigZag Conversion
- 排序算法总结
- [toj1136]Humble Number
- WITH AS实现查找表中指定节点的所有子节点
- 对ISE仿真的理解