I am trying to get the number of golfing sessions that have been attended which exists at position position [1] in the text file and add 1 to it. I have manged to do this but now want to update the integer value. Currently the program just writes the new value on the next line instead of updating.
with open("%s.txt" % month, 'r+') as f:
for line in f:
lineList = line.split(",")
if golferssName == lineList[0]:
numSessions = int(lineList[1])
numSessions = int(numSessions) + 1
ineList[1] = numSessions
f.write(str(lineList[1]))
at the moment the text file looks like this:
Tom Jones,1
2
I want the 2 to be where the 1 is :(