Python学习笔记:AttributeError: 'NoneType' object has no attribute 'text' 解决
程序员文章站
2022-03-26 23:20:17
...
#前言
最近在学习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。
对应于这类错误,以后要更加小心检查大小写。
推荐阅读
-
解决Keras报错AttributeError: 'NoneType' object has no attribute 'inbound_nodes'
-
AttributeError: ‘NoneType‘ object has no attribute ‘origin‘解决办法
-
Python 爬取网页信息 AttributeError :’NoneType’ object has no attribute ’attrs’
-
python-pip升级报错- AttributeError: 'NoneType' object has no attribute 'bytes'
-
python错误:AttributeError: 'module' object has no attribute 'setdefaultencoding'问题的解决方法
-
python错误:AttributeError: 'module' object has no attribute 'setdefaultencoding'问题的解决方法
-
Python学习笔记:AttributeError: 'NoneType' object has no attribute 'text' 解决
-
python报错:AttributeError: 'NoneType' object has no attribute 'append'
-
python报错:AttributeError: 'NoneType' object has no attribute 'append'
-
Python 爬取网页信息 AttributeError :’NoneType’ object has no attribute ’attrs’