python - How to remove item from xml without concurrent modification exception -
i want iterate xml file , delete items. however, way use, not remove issues because of concurrent modification exception. how can resolve issue?
here script:
xml = et.parse(_file) root = xml.getroot() error in root.iter('error'): bmatch = false file = error.find('file').text if file != none: p in _include_patterns: if p in file: bmatch = true break if bmatch == false: root.remove(error) xml.write(_file)
edit modified, iter below , works well:
error in list(root.iter('error')):
Comments
Post a Comment