|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 足迹 于 2017-9-3 15:50 编辑
错误exception
详细见
Python 标准异常总结
http://bbs.fishc.com/thread-45814-1-1.html
(出处: 鱼C论坛)
主要错误
AssertionError
- >>> a=['123']
- >>> assert len(a)>0
- >>> a.pop()
- '123'
- >>> assert len(a)>0
- Traceback (most recent call last):
- File "<pyshell#3>", line 1, in <module>
- assert len(a)>0
- AssertionError
复制代码
AtributeError
- >>> a=[123]
- >>> a.ser()
- Traceback (most recent call last):
- File "<pyshell#5>", line 1, in <module>
- a.ser()
- AttributeError: 'list' object has no attribute 'ser'
复制代码
typeError
- >>> 1+'1'
- Traceback (most recent call last):
- File "<pyshell#6>", line 1, in <module>
- 1+'1'
- TypeError: unsupported operand type(s) for +: 'int' and 'str'
复制代码
zeroDivitionError
- >>> 2/0
- Traceback (most recent call last):
- File "<pyshell#7>", line 1, in <module>
- 2/0
- ZeroDivisionError: division by zero
- >>>
复制代码
IndexError
- >>> a=[1,2,3]
- >>> a[3]
- Traceback (most recent call last):
- File "<pyshell#10>", line 1, in <module>
- a[3]
- IndexError: list index out of range
复制代码
NameError
- >>> b
- Traceback (most recent call last):
- File "<pyshell#11>", line 1, in <module>
- b
- NameError: name 'b' is not defined
复制代码
KeyError
- >>> dict1={'one':1,'two':2,'three':3}]
- >>> dict1['one']
- 1
- >>> dict1['four']
- Traceback (most recent call last):
- File "<pyshell#19>", line 1, in <module>
- dict1['four']
- KeyError: 'four'
复制代码 |
|