ElementTree Write to an XML
<p>What's the easiest way to write an edited XML root to a new file? This is what I have so far and it's throwing <strong>AttributeError: 'module' object has no attribute 'write'</strong> <br>
PS: I can't use any other api besides ElementTree.</p>

<pre><code>import xml.etree.ElementTree as ET
from xml.etree.ElementTree import Element, SubElement, Comment
from ElementTree_pretty import prettify
tree = ET.parse('file-to-be-edited.xml')
root = tree.getroot()

#Process XML here

ET.write('file-after-edits.xml')
</code></pre>

<p>Your <code>tree</code> is a <code>ElementTree</code> object which provides a <a href="https://docs.python.org/3/library/xml.etree.elementtree.html#xml.etree.ElementTree.ElementTree.write" rel="nofollow"><code>write()</code></a> method to write the tree. For example:</p>

<pre><code>#Process XML here
tree.write('file-after-edits.xml', encoding='utf8')
</code></pre>

python xml elementtree