I have a .txt file in which I want to replace a specific line (line #3) with a string. I don't want to use a simple file.replace(targetString, newString) because I have multiple targetString in the file, and the orders in which they're in is unknown. I do know that the string I want to replace is always at the 3rd line, and it is the only thing on the 3rd line.
Currently my code looks something like this, I'm terrible at programming so I would appreciate the easiest answer you can think of
with open("LAB5INFO.txt", "r+") as file:
content = file.read()
file.seek(0)
file.truncate()
file.write(content.replace(<<LINE3>>, string))