I have a txt file containing data that I need to open in a python file and perform a calculation on. A sample of the data file is as follows:
1,22/01/2019,30
2,22/01/2019,40
3,22/01/2019,350
1,23/01/2019,45
2,25/01/2019,10
4,26/01/2019,750
2,29/01/2019,15
1,31/01/2019,50
I need to create a code that adds together the ending numbers from every line that starts with the number one (as an example it would need to add 30, 45, etc) I have tried using str.strip and it has not been working out please help!
the code I tried was
with open('events.txt') as fn:
content = fn.readlines()
for line in content:
if(line.startswith('1')):
priceUnit=int(str.strip([0:13]))
edit
and include your try with usingstr.strip()
to show us how it has not been working. Also, have you triedstr.strip().split()
?