title: Python/XML: Pretty-printing ElementTree
body: <p>I construct XML using <a href="https://docs.python.org/2/library/xml.etree.elementtree.html" rel="nofollow noreferrer">The ElementTree XML API</a> and I would like to be able to pretty-print</p>
  
  <ul>
  <li>individual nodes (for inspection) as well as </li>
  <li>the whole document (to a file, for future examination).</li>
  </ul>
  
  <p>I can use use <a href="https://docs.python.org/2/library/xml.etree.elementtree.html#xml.etree.ElementTree.ElementTree.write" rel="nofollow noreferrer"><code>ET.write()</code></a> to write my XML to file and then pretty-print it using many suggestions in <a href="https://stackoverflow.com/q/749796/850781">Pretty printing XML in Python</a>. However, this requires me to serialize and then deserialize the XML (to disk or to <a href="https://docs.python.org/2/library/stringio.html" rel="nofollow noreferrer">StringIO</a>) just to serialize it again prettily - which is clearly suboptimal.</p>
  
  <p>So, is there a way to pretty-print an <code>xml.etree.ElementTree</code>?</p>