Avatar ·

Record to a specific line on Python

📁 question

There was a need to write data to a specific line in a large file of a couple of gigs. More specifically, I need to read a line, then process it, and then delete it from the text file.

I found a solution that involves reading the entire file into a variable, then making changes to the variable and writing everything out again, but for a large amount of data, this is obviously not the best option.

Is there a simpler way? If not, then the question itself is: how to write data to a specific line without rewriting the entire file?