lxml --pretty_print--写文件问题 [英] lxml --pretty_print-- write file problem
问题描述
我正在将原始数据写入xml文件python程序,在我的设计中,我们逐行获取原始数据, 然后将其写入xml文件,例如:
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>
我第一次用pretty_print = True写入xml文件时,我得到了我想要的东西,但是第二次 每当我读取文件时,获取元素根目录--add--新元素,然后使用pretty_print = True将其保存回去,但我却无法获得想要的东西,就像这样:
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>
` lxml怎么了?还是我的错?
` what's wrong with lxml? Or my fault?
推荐答案
You might find the answer in the lxml faq: Why doesn't the pretty_print option reformat my XML output?
这篇关于lxml --pretty_print--写文件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!