我正在尝试使用XML中的tostring方法,以字符串的形式获得XML的“漂亮”版本。lxml站点上的示例显示了以下示例:
>>> import lxml.etree as etree
>>> root = etree.Element("root")
>>> print(root.tag)
root
>>> root.append( etree.Element("child1") )
>>> child2 = etree.SubElement(root, "child2")
>>> child3 = etree.SubElement(root, "child3")
>>> print(etree.tostring(root, pretty_print=True))
<root>
<child1/>
<child2/>
<child3/>
</root>
然而,我的输出,运行这些确切的行是:
b'<root>\n <child1/>\n <child2/>\n <child3/>\n</root>\n'
我安装的lxml版本中是否存在错误?教程中的逐字例句不起作用似乎很奇怪。
目前没有回答
相关问题 更多 >
编程相关推荐