How do I get Python’s ElementTree to pretty print to an XML file?

xml.etree.ElementTree.indent(tree, space=" ", level=0) Appends
whitespace to the subtree to indent the tree visually. This can be
used to generate pretty-printed XML output. tree can be an Element or
ElementTree. space is the whitespace string that will be inserted for
each indentation level, two space characters by default. For indenting
partial subtrees inside of an already indented tree, pass the initial
indentation level as level.