[Record it] Error reporting AttributeError: 'NoneType' object has no attribute 'text'

[Record it] Error reporting AttributeError: 'NoneType' object has no attribute 'text'

question

The following error occurs when running the xml to txt file
insert image description here

The reason is that some of the different xml files may still exist <difficult>0</difficult>, and some files do not. This problem cannot be solved in the original code.
The original code is as follows:
insert image description here

Solution

Change it to the following

 #difficult = obj.find('difficult').text
        if obj.find('difficult'):
            difficult = int(obj.find('difficult'.text))
        else:
            difficult = 0

insert image description here
Subsequent runs succeed.

Source: Log Error: AttributeError: 'NoneType' object has no attribute 'text'

Guess you like

Origin blog.csdn.net/weixin_45768644/article/details/129865608