Skip to content

Instantly share code, notes, and snippets.

@donlovett
Created September 22, 2016 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donlovett/3dffedb7cf0d3c8003930f534ebd1ab3 to your computer and use it in GitHub Desktop.
Save donlovett/3dffedb7cf0d3c8003930f534ebd1ab3 to your computer and use it in GitHub Desktop.
update with stats labeled and debut prints out
import xml.etree.ElementTree as ET
#fname = raw_input('Enter the file name: ')
#fname = '/home/vagrant/Coursera/Week5/comments_42.xml'
fname = '/home/vagrant/Coursera/Week5/comments_318170.xml'
try:
tree = ET.ElementTree(file=fname)
print 'Retreived ',fname
#Retrieved 4204 characters
except:
print 'File cannot be opened:', fname
exit()
root = tree.getroot()
mycounter = 0
mysum = 0
#stuff = ET.fromstring(input)
lst = root.findall('comments/comment')
#print 'Comment count:', len(lst)
for item in lst:
#print 'Name', item.find('name').text
#print 'Count', item.find('count').text
mycounter = mycounter + 1
mysum = mysum + int(item.find('count').text)
print 'Count - Number of Elements', mycounter
print 'Sum - Count Attribute', mysum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment