how "reset" etree using lxml in python 2.7?
i have 1 file contains list of files. each of files in list store information in element tree in lxml, write lxml file. i'd able once write file restore etree initial state.
conceptually i'm at:
from lxml import etree file in list: quiz = etree.element('quiz') open file , process contents: "add bunch of stuff etree" etree.subelement(quiz,'stuff') "print etree xml file" dataout = etree.tostring(quiz, pretty_print = true) output_file.write(dataout) "reset etree blank file"
i don't see issues following setup similar 1 have:
from lxml import etree item in ["test1", "test2", "test3"]: quiz = etree.element('quiz') etree.subelement(quiz, 'stuff', attrib={"attr": item}) print etree.tostring(quiz, pretty_print = true) print "---"
which prints:
<quiz> <stuff attr="test1"/> </quiz> --- <quiz> <stuff attr="test2"/> </quiz> --- <quiz> <stuff attr="test3"/> </quiz> ---
i don't see quizzes stack means problem somewhere else in real code.
Comments
Post a Comment