标签:visio pos 存在 top tmp 文件 访问 key tee
try: name = [‘a‘,‘b‘,‘c‘] name[5] ##定义错误的索引,IndexError info_dic = {} info_dic[‘a‘] ##定义错误的键值,KeyError except IndexError: print ‘Your list is out of range...‘ except KeyError: print ‘Your dic is out of key... ‘ ##except (IndexError,KeyError): 等同上面,同时抓取两个错误
#!/usr/bin/python # -*- coding: UTF-8 -*- try: fh = open("testfile", "w") fh.write("这是一个测试文件,用于测试异常!!") finally: print "Error: 没有找到文件或读取文件失败"
$ python test.py
Error: 没有找到文件或读取文件失败
try: 10/0 except Exception as e: print ‘aaaaaaa‘, e raise e else: print(‘ok‘) finally: print(‘finally‘) print(‘hello world‘)
aaaaaaa integer division or modulo by zero Traceback (most recent call last): finally File "E:/test/test.py", line 11, in <module> raise e ZeroDivisionError: integer division or modulo by zero
<wiz_tmp_tag id="wiz-table-range-border" contenteditable="false" style="display: none;">
标签:visio pos 存在 top tmp 文件 访问 key tee
原文地址:http://www.cnblogs.com/song-liang/p/7807018.html