Parsing XML documentation has a gotcha for noobies...
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
lxml |
Fix Released
|
Low
|
scoder |
Bug Description
As a Python Noob, I hesitate to mention this; however, there seems to be a strange gotcha in the [documentation](http://
Learning the parsing operations I was simply copying and pasting these instructions,
[code]
>>> from lxml import etree
[...]
>>> xml = '<a xmlns="test"><b xmlns="test"/></a>'
>>> root = etree.fromstrin
>>> etree.tostring(
b'<a xmlns="test"><b xmlns="test"/></a>'
[...]
>>> tree = etree.parse(
>>> etree.tostring(
b'<a xmlns="test"><b xmlns="test"/></a>'
[/code]
first I got the error,
At NameError: name 'StringIO' is not defined
I recognized the StringIO module likely needed to be imported. But the fix
>>> from StringIO import StringIO
is not described in the documentation and involves a gotcha a Noob may not expect and other Python programmers admit is [strange] (https:/
----
>>> print("%-20s: %s" % ('lxml.etree', etree.LXML_
lxml.etree : (3, 3, 0, -95)
>>> print("%-20s: %s" % ('libxml used', etree.LIBXML_
libxml used : (2, 9, 1)
>>> print("%-20s: %s" % ('libxml compiled', etree.LIBXML_
libxml compiled : (2, 9, 1)
>>> print("%-20s: %s" % ('libxslt used', etree.LIBXSLT_
libxslt used : (1, 1, 28)
>>> print("%-20s: %s" % ('libxslt compiled', etree.LIBXSLT_
libxslt compiled : (1, 1, 28)
---
StringIO is a bit tricky because it was moved around in Py3. But it's generally available as "io.StringIO" these days. I added that to the docs. Thanks for the suggestion.