I am doing a project and in it I have to frequently edit a file from the position somewhere in the center. I want to go to the 2 characters left to the position from where the word 'rules' starts.
I have tried something like this:
with open("file.txt", "r+") as fh:
content = fh.read()
index = content.seek("rules") - 2
But it takes me to the two lines up instead of taking to two characters back.
This is how the file look:
rule1
rule2
rule3
rule4
.
.
.
.
rule100
rules are very good.
So, basically it is the last line of the file which starts with 'rules' and I want to go at the end of the line that is starting with 'rule100' and write a new line that will be something 'rule101' and save the file.