title: How do I extract value of XML attribute in Python?
body: <p>I need to extract the value of an attribute in an XML document using Python.</p>
  
  <p>For example, If I have an XML document like this:</p>
  
  <pre><code>&lt;xml&gt;
      &lt;child type = "smallHuman"/&gt;
      &lt;adult type = "largeHuman"/&gt;
  &lt;/xml&gt;
  </code></pre>
  
  <p>How would I be able get the text 'smallHuman' or 'largeHuman' to store in a variable?</p>
  
  <p>Edit: I'm very new to Python and may require a lot of assistance.</p>
  
  <p>This is what I've tried so far:</p>
  
  <pre><code>#! /usr/bin/python
  
  import xml.etree.ElementTree as ET
  
  
  def walkTree(node):
      print node.tag
      print node.keys()
      print node.attributes[]
      for cn in list(node):
          walkTree(cn)
  
  treeOne = ET.parse('tm1.xml')
  treeTwo = ET.parse('tm3.xml')
  
  walkTree(treeOne.getroot())
  </code></pre>
  
  <p>Due to the way this script will be used, I cannot hard-code the XML into the .py file.</p>