python - ElementTree 漂亮打印空行
问题描述
我正在使用下面的代码行在 python 2.7 中漂亮地打印 elementtree 对象:
xml_str = minidom.parseString(ET.tostring(tgt_xml.getroot())).toprettyxml(indent="\t", encoding='utf-8')
with open(final_path, "w") as f:
f.write(xml_str)
它完成了它的工作,但在每行 xml 之后添加了 2 个空白行......所以结果看起来像
<Workflow name="Some_name">
<taskWorkflow>
<taskWorkflow retainSysIds="false">
<variables>
<variable>
<description/>
有人知道如何在没有空行的情况下打印 elementtree 吗?
解决方案
推荐阅读
- go - NATS 订阅后只接收消息
- woocommerce-rest-api - 产品 ID 的 woocommerce REST API 评级
- android - IP地址范围的网络安全配置?
- android - 如何将可渲染的小节点放置在可渲染的较大节点的相同位置?
- python - Psychopy/Python - 访问冲突读取 0x00000010
- ruby - 将 Capybara 屏幕截图保存到功能文件夹
- javascript - 如何通过 html 选择使用 javascript 移动 html 内容
- java - 从多个路径从 Firebase 数据库获取数据
- python - 气象站项目中的KeyError
- maven - TFS 2018 神器 maven 可以支持上游 repo 吗?