lxml --pretty_print--写文件问题 [英] lxml --pretty_print-- write file problem

查看:84
本文介绍了lxml --pretty_print--写文件问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将原始数据写入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?

推荐答案

您可能会在lxml常见问题解答中找到答案:

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

这篇关于lxml --pretty_print--写文件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆