Error writing XML file in Python appeared AttributeError: 'str' object has no attribute 'dom'

Error writing XML file in Python appeared AttributeError: 'str' object has no attribute 'dom'

当我写 xml 时,出现了这个错误:AttributeError: 'str' object has no attribute 'dom' 我不知道该怎么办...

enter image description here

当您执行 import xml.dom.minidom 时,您将导入 xml。但是,您当然也使用 xml 作为全局变量。所以,全局变量隐藏了导入的模块。

为您的变量使用不同的名称,例如 treexml_tree 是常见的选择。