Python 3.x Etree无法打印
为什么Python 3.x Etree无法打印,python-3.x,xml,xml-parsing,lxml,Python 3.x,Xml,Xml Parsing,Lxml,为什么Etree无法打印 我在repl.it中运行了以下程序: library.xml <?xml version="1.0" encoding="utf-8"?> <library attrib1="att11" attrib2="att22"> library-text <book isbn="1111111111"> <
Etree
无法打印
我在repl.it中运行了以下程序:
library.xml
<?xml version="1.0" encoding="utf-8"?>
<library attrib1="att11" attrib2="att22">
library-text
<book isbn="1111111111">
<title lang="en">T1 T1 T1 T1 T1</title>
<date>2001</date>
<author>A1 A1 A1 A1 A1</author>
<price>10.00</price>
</book>
<book isbn="2222222222">
<title lang="en">T2 T2 T2 T2 T2</title>
<date>2002</date>
<author>A2 A2 A2 A2 A2</author>
<price>20.00</price>
</book>
<book isbn="3333333333">
<title lang="en">T3 T3 T3 T3</title>
<date>2003</date>
<author>A3 A3 A3 A3 A3y</author>
<price>30.00</price>
</book>
</library>
输出
b'<library attrib1="att11" attrib2="att22">\n\tlibrary-text\n\t<book isbn="1111111111">\n\t\t<title lang="en">T1 T1 T1 T1 T1</title>\n\t\t<date>2001</date>\n\t\t<author>A1 A1 A1 A1 A1</author>\t\t\n\t\t<price>10.00</price>\n\t</book>\n\t<book isbn="2222222222">\n\t\t<title lang="en">T2 T2 T2 T2 T2</title>\n\t\t<date>2002</date>\n\t\t<author>A2 A2 A2 A2 A2</author>\t\t\n\t\t<price>20.00</price>\n\t</book>\n\t<book isbn="3333333333">\n\t\t<title lang="en">T3 T3 T3 T3</title>\n\t\t<date>2003</date>\n\t\t<author>A3 A3 A3 A3 A3y</author>\t\t\n\t\t<price>30.00</price>\n\t</book>\n</library>\n'
b'\n\t图书馆文本\n\t\n\t\tT1 T1\n\t\t2001\n\t\tA1 A1\t\t\n\t\t10.00\n\t\n\t\n\t\T2 t2t2\n\t\t2002\n\t\t\tA2 A2 A2\t\t\n\t\t\t20.00\n\t\n\t\n\t\t\t\t33 T3 T3 T3 T3 T3 T3 T3 T3 A3 A3 A3\t\t\t\t\n
使用中的decode()
进行尝试
print(xmlText.decode())
看看它是否有效。为什么需要
decode()
?@user366312b中的b
print(xmlText.decode())