我从以下代码中收到错误:
import xml.etree.ElementTree as ET
tree = ET.ElementTree()
root = ET.Element("configuration")
elem = ET.SubElement(root, "appConfig")
elem2 = ET.SubElement(root, "fileGDB")
print ET.tostring(root)
tree.write(sys.stdout)
它在 ElementTree.py 模块中的以下行引发异常: iterate = elem.getiterator # cET compatible 异常是: AttributeError: 'NoneType' object has no attribute 'getiterator'
在上面的代码中:
print ET.tostring(root)
打印出来就好了。我不明白为什么它会抛出这个异常。我究竟做错了什么?
史蒂夫