XML : Extracting XML data in Python: Data prints, but the sum is not being returned

My code compiles and returns the data in the output. I asked for the sum of the numbers to get printed, and the program won't print it. Is something wrong with my sum statement? Should I separate the print statements?

Here is what I have written:

  import urllib  import xml.etree.ElementTree as ET    serviceurl = 'http://python-data.dr-chuck.net/comments_42.xml'  while True:      url = serviceurl + urllib.urlencode({'sensor':'false', 'address': 'address'})      print ('Retrieving', url)      uh = urllib.urlopen(url)      data = uh.read()      print ('Retrieved',len(data),'characters')      print (data)      tree = ET.fromstring(data)      results = tree.findall('.//count')  print (results, sum(results))    

This shows what the XML data looks like:

  <comment>    <name>Matthias</name>    <count>97</count>  </comment>    

No comments:

Post a Comment