【发布时间】:2023-03-11 08:11:01
【问题描述】:
from elementtree import ElementTree as ET
tree= ET.parse(r'N:\myinternwork\files xml of bus systems\testonieeebus.xml','r')
root= tree.getroot()
print(root)
现在错误在输出中,因为它没有给出任何结果
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book category="cooking">
<author>Giada De Laurentiis</author>
</book>
</bookstore>
【问题讨论】:
-
ET= open(…)覆盖了 ET 的先前定义; ET 现在是一个打开的文件,文件没有“解析”属性。 -
Python 自带的
ElementTree模块在xml.etree包中。见docs.python.org/2.7/library/xml.etree.elementtree.html。但是您使用的是from elementtree import ElementTree as ET。为什么?
标签: python xml file xml-parsing elementtree