lxml --pretty_print— write file problem

你离开我真会死。 提交于 2019-12-24 03:51:12

问题


I am write a raw data to xml file python program, in my design,we get the raw data line by line, then write it into xml file like:

`<root>\n
  <a> value </a>\n
  <b> value </b>\n
</root>

The first time i write into xml file with pretty_print=True, i got what i want, but when the second time i read the file, get the element root, --add-- new elemnts then save it back with pretty_print=True, but i can not get what i want,it just like:

...\n
<c> value </c></root>

` what's wrong with lxml? Or my fault?


回答1:


You might find the answer in the lxml faq: Why doesn't the pretty_print option reformat my XML output?



来源:https://stackoverflow.com/questions/4407108/lxml-pretty-print-write-file-problem

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!