title: Python: ElementTree, get the namespace string of an Element
body: <p>This XML file is named <code>example.xml</code>:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
  
    &lt;modelVersion&gt;14.0.0&lt;/modelVersion&gt;
    &lt;groupId&gt;.com.foobar.flubber&lt;/groupId&gt;
    &lt;artifactId&gt;uberportalconf&lt;/artifactId&gt;
    &lt;version&gt;13-SNAPSHOT&lt;/version&gt;
    &lt;packaging&gt;pom&lt;/packaging&gt;
    &lt;name&gt;Environment for UberPortalConf&lt;/name&gt;
    &lt;description&gt;This is the description&lt;/description&gt;    
    &lt;properties&gt;
        &lt;birduberportal.version&gt;11&lt;/birduberportal.version&gt;
        &lt;promotiondevice.version&gt;9&lt;/promotiondevice.version&gt;
        &lt;foobarportal.version&gt;6&lt;/foobarportal.version&gt;
        &lt;eventuberdevice.version&gt;2&lt;/eventuberdevice.version&gt;
    &lt;/properties&gt;
    &lt;!-- A lot more here, but as it is irrelevant for the problem I have removed it --&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>If I load example.xml and parse it with ElementTree I can see its namespace is <code>http://maven.apache.org/POM/4.0.0</code>.</p>
  
  <pre><code>&gt;&gt;&gt; from xml.etree import ElementTree
  &gt;&gt;&gt; tree = ElementTree.parse('example.xml')
  &gt;&gt;&gt; print tree.getroot()
  &lt;Element '{http://maven.apache.org/POM/4.0.0}project' at 0x26ee0f0&gt;
  </code></pre>
  
  <p>I have not found a method to call to get just the namespace from an <code>Element</code> without resorting to parsing the <code>str(an_element)</code> of an Element. It seems like there got to be a better way.</p>