python中AttributeError异常的介绍

148 python中AttributeError异常的介绍-大盘站插图

1、当你访问一个对象的属性,但是这个属性没有被这个对象定义时,导致AttributeError。

2、AttributeError的错误信息行告诉我们特定对象类型没有访问属性。点击文件链接可以快速定位到具体的错误代码的位置。

实例

a_list=(1,2)
a_list.append(3)
运行之后抛出异常信息
Traceback(mostrecentcalllast):
File"/Users/chenxiangan/pythonproject/demo/exmpale.py",line2,in<module>
a_list.append(3)
AttributeError:'tuple'objecthasnoattribute'append'