import re
def ReadText()
total = 0
text_file = open('Heliatext.txt', 'r')
lines = text_file.read()
numblist = []
print(lines)
print(len(lines))
stuff = re.findall(r'\d+', lines)
numblist.append(stuff)
print(numblist)
for x in numblist:
total += x
print (total)
text_file.close()
ReadText()
Hi all, so i'm trying to scrape a simple text file for integers, put them into a list, and then add them all together. I've been looking throughout stackoverflow for how to do this and as far as i can tell, this way should work but i keep on getting this error
Traceback (most recent call last): File "C:/Users/chris/Desktop/Helia.py", line 32, in ReadText() blah blah, 1 File "C:/Users/chris/Desktop/Helia.py", line 28, in ReadText total += x TypeError: unsupported operand type(s) for +=: 'int' and 'list'
file contents are this:
blah blah, 1 this is in he3lia's file 6
Any help and insight is appreciated. You guys are awesome!