Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

_ElementInterface instance has no attribute 'tostring'

Tags:

python

The code below generates this error. I can't figure out why. If ElementTree has parse, why doesn't it have tostring? http://docs.python.org/library/xml.etree.elementtree.html#xml.etree.ElementTree.ElementTree

from xml.etree.ElementTree import ElementTree

...

tree = ElementTree()
node = ElementTree()

node = tree.parse(open("my_xml.xml"))
text = node.tostring()
like image 732
Alex Avatar asked Dec 29 '22 01:12

Alex


1 Answers

tostring is a method of the xml.etree.ElementTree module, not the confusingly similarly-named xml.etree.ElementTree.ElementTree class.

from xml.etree.ElementTree import ElementTree
from xml.etree.ElementTree import tostring

tree = ElementTree()
node = tree.parse(open("my_xml.xml"))
text = tostring(node)
like image 88
John Kugelman Avatar answered Dec 31 '22 14:12

John Kugelman