lxml中tostring的pretty_print选项不起作用
我正在尝试在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版本是不是有问题?感觉教程中的逐字示例怎么会不管用呢。