possible bug: parse() and fromstring() have different results
Basically, I would expect ET.parse(StringIO(test_string)) and ET.fromstring(test_string) to return the same data. Instead, parse() returns an ElementTree, and fromstring() returns an Element. ---- from StringIO import StringIO from lxml import etree as ET test_string = """<root>data</root>""" tree1 = ET.parse(StringIO(test_string)) tree2 = ET.fromstring(test_string) print ET.tostring(tree1), type(tree1) print ET.tostring(tree2), type(tree2) ---- Output: <root>data</root> <type 'lxml.etree._ElementTree'> <root>data</root> <type 'lxml.etree._Element'>
Oh, and you'll probably want this: Python : sys.version_info(major=2, minor=7, micro=6, releaselevel='final', serial=0) lxml.etree : (3, 4, 0, 0) libxml used : (2, 9, 1) libxml compiled : (2, 9, 1) libxslt used : (1, 1, 28) libxslt compiled : (1, 1, 28) This is on Windows. On Tue, September 23, 2014 2:48 pm, tcqwerty@emhsoft.com wrote:
Basically, I would expect ET.parse(StringIO(test_string)) and ET.fromstring(test_string) to return the same data. Instead, parse() returns an ElementTree, and fromstring() returns an Element. ---- from StringIO import StringIO from lxml import etree as ET test_string = """<root>data</root>""" tree1 = ET.parse(StringIO(test_string)) tree2 = ET.fromstring(test_string) print ET.tostring(tree1), type(tree1) print ET.tostring(tree2), type(tree2) ---- Output: <root>data</root> <type 'lxml.etree._ElementTree'> <root>data</root> <type 'lxml.etree._Element'>
tcqwerty@emhsoft.com schrieb am 23.09.2014 um 23:48:
Basically, I would expect ET.parse(StringIO(test_string)) and ET.fromstring(test_string) to return the same data. Instead, parse() returns an ElementTree, and fromstring() returns an Element. ---- from StringIO import StringIO from lxml import etree as ET test_string = """<root>data</root>""" tree1 = ET.parse(StringIO(test_string)) tree2 = ET.fromstring(test_string) print ET.tostring(tree1), type(tree1) print ET.tostring(tree2), type(tree2) ---- Output: <root>data</root> <type 'lxml.etree._ElementTree'> <root>data</root> <type 'lxml.etree._Element'>
participants (2)
-
Stefan Behnel
-
tcqwerty@emhsoft.com