Python学习笔记:AttributeError: 'NoneType' object has no attribute 'text' 解决

#前言
最近在学习python,犯了很多低级错误,总结一下
#问题
AttributeError: ‘NoneType’ object has no attribute ‘text’
#出处

difficult = obj.find('difficult').text

方案

错误提示的是空元素,没有对应的属性。

<object>
    <name>1</name>
    <pose>Unspecified</pose>
    <truncated>0</truncated>
    <Difficult>0</Difficult>

仔细查看可知,原文档中是Difficult而不是difficult。
对应于这类错误,以后要更加小心检查大小写。

猜你喜欢

转载自blog.csdn.net/lvsehaiyang1993/article/details/80910104
今日推荐