在用"丑陋"的XML读取现有文件并进行一些修改后,漂亮的打印不起作用.我试过了etree.write(FILE_NAME, pretty_print=True).
我有以下XML:
<testsuites tests="14" failures="0" disabled="0" errors="0" time="0.306" name="AllTests">
<testsuite name="AIR" tests="14" failures="0" disabled="0" errors="0" time="0.306">
....
Run Code Online (Sandbox Code Playgroud)
我这样使用它:
tree = etree.parse('original.xml')
root = tree.getroot()
...
# modifications
...
with open(FILE_NAME, "w") as f:
tree.write(f, pretty_print=True)
Run Code Online (Sandbox Code Playgroud)