尝试从 xml 文档中删除元素时出现以下错误。“ValueError: list.remove(x): x not in list” 这是代码,错误发生在删除的那一行。
import xml.etree.ElementTree as ET
tree = ET.parse("AddInClasses.xml")
rootElem = tree.getroot()
for class2 in rootElem.findall("Transforms/class"):
name2 = class2.find("name")
if name2.text == "Get Field":
rootElem.remove(class2)
tree.write("AddInClassesTrimmed.xml")