【发布时间】:2022-01-21 17:19:24
【问题描述】:
我在 etree 的 write func 中添加了 short_empty_elements=False,这样当我有一个空元素时,例如 ,它会以这种格式写入:
<root>
<t></t>
</root>
我的问题是我需要它在单独的行中,像这样:
<root>
<t>
</t>
</root>
我不知道该怎么做。
.text='\n' 或 .text='' 都不起作用。
有什么办法吗?
【问题讨论】:
-
你为什么要这么做?
标签: python xml elementtree