python中AttributeError異常的介紹
1、當(dāng)你訪(fǎng)問(wèn)一個(gè)對(duì)象的屬性,但是這個(gè)屬性沒(méi)有被這個(gè)對(duì)象定義時(shí),導(dǎo)致AttributeError。
2、AttributeError的錯(cuò)誤信息行告訴我們特定對(duì)象類(lèi)型沒(méi)有訪(fǎng)問(wèn)屬性。點(diǎn)擊文件鏈接可以快速定位到具體的錯(cuò)誤代碼的位置。
實(shí)例
a_list=(1,2)
a_list.append(3)
運(yùn)行之后拋出異常信息
Traceback(mostrecentcalllast):
File"/Users/chenxiangan/pythonproject/demo/exmpale.py",line2,in
a_list.append(3)
AttributeError:'tuple'objecthasnoattribute'append'
以上內(nèi)容為大家介紹了python培訓(xùn)之AttributeError異常的介紹,希望對(duì)大家有所幫助,如果想要了解更多Python相關(guān)知識(shí),請(qǐng)關(guān)注IT培訓(xùn)機(jī)構(gòu):千鋒教育。