用这个怎么样:
但是,使用collections.OrderedDict()而不是简单字典来保持顺序。有了字典之后,很容易从中获取和格式化文本:
使用@Colt 45溶液:import xml.etree.ElementTree
import collections
s = """\
"""
table = xml.etree.ElementTree.XML(s)
rows = iter(table)
headers = [col.text for col in next(rows)]
for row in rows:
values = [col.text for col in row]
for key, value in collections.OrderedDict(zip(headers, values)).iteritems():
print key, value
输出:
^{pr2}$