Created
September 22, 2016 18:14
-
-
Save donlovett/3dffedb7cf0d3c8003930f534ebd1ab3 to your computer and use it in GitHub Desktop.
update with stats labeled and debut prints out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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