Python格式化xml文件 在使用Python构建XML文件的时候,默认是没有缩减的。 发现BeautifulSoup自带自动缩减 方法如下: 123456from bs4 import BeautifulSoupbs = BeautifulSoup(open(tmp_file), 'xml')with open(filename, 'w', encoding='utf-8') as f: f.write(bs.prettify()) Python #文件操作 #XML Python格式化xml文件 https://iyuluo.com/2020/03/15/Python格式化xml文件/ 作者 yuluo 发布于 2020年3月15日 许可协议 Python 创建XML文件 上一篇 Python 格式化时间 下一篇