繁体   English   中英

xml.etree.ElementTree - .remove()功能的问题

[英]xml.etree.ElementTree - problem with .remove() functionality

我有xml.etree.ElementTree remove()函数的问题。 我正在从字符串解析数据到我的程序,并希望删除与给定列表中的模式匹配的元素(我的代码中的self.given_list),但是当我启动程序时,它显示错误:

ValueError: list.remove(x): x not in list

即使我在上面打印它,我也能看到它存在。 代码如下所示:

     target_view_config = ET.fromstring(source_view_config)
     for source_item in target_view_config.findall('jobNames/string'):
             for target_item in self.given_list:
                 if((source_item.text) == target_item):
                     target_view_config.remove(source_item)
                     break

好吧,我通过调用一个对象来自己解决它

object = target_view_config.find('jobNames')
object.remove(source_item)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM