I am trying to add a text in a line while looping the file in append and read mode. Below is the code that does not work i.e. does not write the text in the middle of loop line.
file = open('path/to/file.txt','a+')
file.seek(0, 0)
line=file.readline()
while line:
if line=="2ND LINE":
file.write(",new text")
line=file.readline()
file.close()
What I am trying to do:
1ST LINE
2ND LINE,new text
3RD LINE