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

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -