On 31/08/14 19:32, Alex Kleider wrote:

total = 0
with open('/Users/richarddillon/Desktop/numbers.txt', 'r') as infile:
    for line in infile:
        total += float(line)
print(total)

..but isn't there a problem if the file contains empty lines?

Yes you are right. And my second reply did point out that
the OP would need to add some lines to catch any such
non-conformities in his data.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to