[issue1572710] cElementTree.SubElement doesn't recognize keyword "attrib"
Dave Abrahams
report at bugs.python.org
Sat Apr 21 04:05:24 CEST 2012
Dave Abrahams <dave at boostpro.com> added the comment:
@effbot, I think you may have misread the OP's example. The first two arguments /are/ being passed positionally. In any case, there's a real bug here. cElementTree seems to choke on uses of attrib. Change cElementTree to ElementTree below and this one works, too.
>>> from xml.etree.cElementTree import Element, tostring
>>> print tostring(Element('foo', attrib={}))
Traceback (most recent call last):
File "bug.py", line 2, in <module>
print tostring(Element('foo', attrib={}))
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 1127, in tostring
ElementTree(element).write(file, encoding, method=method)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 821, in write
serialize(write, self._root, encoding, qnames, namespaces)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 933, in _serialize_xml
v = _escape_attrib(v, encoding)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 1093, in _escape_attrib
_raise_serialization_error(text)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 1053, in _raise_serialization_error
"cannot serialize %r (type %s)" % (text, type(text).__name__)
TypeError: cannot serialize {} (type dict)
----------
nosy: +dabrahams
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue1572710>
_______________________________________
More information about the Python-bugs-list
mailing list