title: Python script to remove all comments from XML file
body: <p>I am trying to build a python script that will take in an XML document and remove all of the comment blocks from it.</p>
  
  <p>I tried something along the lines of:</p>
  
  <pre><code>tree = ElementTree()
  tree.parse(file)
  commentElements = tree.findall('//comment()')
  
  for element in commentElements:
      element.parentNode.remove(element)
  </code></pre>
  
  <p>Doing this yields a weird error from python: "KeyError: '()'</p>
  
  <p>I know there are ways to easily edit the file using other methods ( like sed ), but I have to do it in a python script. </p>