Skip to content Skip to sidebar Skip to footer

Python Write Xml With Spacing

Is there a way to write XML files in python using the XML library that aren't in one line I have this code: import xml.etree.ElementTree as ET perm = ET.Element('perm') connect = E

Solution 1:

One way to fix this is to use lxml instead of xml. It is a drop-in replacement so you only have to change your import statement to

from lxml import etree asET

and your output statement to

print(ET.tostring(tree,pretty_print=True),file=open('permission-backup.xml','w'))

This is a Python 3 style print() function call so you need to do

from __future__ import print_function

if you don't already.

Post a Comment for "Python Write Xml With Spacing"