I'm attempting to run the following bit of code in python.
import re
text = 'Hello 16 Hello 22 Hello 81 Hello 50'
sum = 0
for m in re.finditer('Hello', text):
print('found', m.start(), m.end())
a = m.end()
b = m.end()+3
print (text[a:b])
block = str(text[a:b])
sum += block
print (sum)
I am continually getting this error:
TypeError: unsupported operand type(s) for +=: 'int' and 'str'
All I want to do is have my code parse through the text and add together specified numbers contained in it.
Does anyone know what I'm doing wrong?
Thanks
castthe matched block into an int before summing.sum = sum + blockwill have exactly the same error assum += block.