【发布时间】:2012-03-28 18:19:14
【问题描述】:
我有一个小型 xml-parsing python sn-p 可以与 ElementTree 一起使用,但不能与 cElementTree 一起使用。这是为什么呢?
#!/usr/bin/python3
import sys
import xml.etree.cElementTree as ET
tree = ET.parse(sys.stdin)
这引发了异常:
cElementTree.ParseError: no element found: line 1, column 0
当它像这样调用时
echo "<a><b>c</b></a>" | ./xmltest.py
编辑:我刚刚注意到 sn-p 在 python 2.7.2 中有效,但在 python 3.2.2 或 3.1.4 中无效,知道为什么吗?
更新:似乎在 python 3.3 中已修复
【问题讨论】:
-
你见过this SO问题吗?您的案例是 unicode 问题吗?
-
虽然这似乎是相关的,但我认为我不能用 utf8 编码“重新打开” sys.stdin,对吧?
标签: python xml python-3.x elementtree celementtree