XML : XML ElementTree: How to sum items from fromstring() with Python

First of all, apologies for the poorly worded question but I'm trying to explain this the best way possible.

I'm looking through some XML and want to sum all the items that I get out of it. At the moment I'm able to extract and print the 100 and 97, but I don't know how to use the "item.find('count').text" and convert them to integers, append them to a list and loop through them to add them together. I feel like I'm quite close, but I'm just not comfortable with finishing this off and I've tried a lot!

  import urllib  import xml.etree.ElementTree as ET    input = '''<commentinfo>  <comments>      <comment>          <name>Leven</name>          <count>100</count>      </comment>      <comment>          <name>Mahdiya</name>          <count>97</count>      </comment>  </comments>  </commentinfo>'''    stuff = ET.fromstring(input)  lst = stuff.findall('comments/comment')    for item in lst:       print item.find('count').text    

No comments:

Post a Comment