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

Popular posts from this blog

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -