I am trying to keep a file with only 10 entries.
Every time that I write a new one, the oldest entry is replaced by the newest; so the total lines is always 10.
example of the file:
abcde-12345
akmjk-13249
ofdsi-01230
faaoj-10293
famdk-05931
foajq-10592
xmdsj-19234
boxqa-12130
fdlsp-95392
paidf-19341
When I add a new line with the append command on this file, it goes to increase the total lines of the file, so the file grows every time I add a line. The objective is to append the line at the bottom, removing the first line of the file, so the oldest entry is removed and the new added at the bottom, leaving the total number of lines in the file, always equal to 10.
My approach has been to
-read the file
-save the last 9 lines in a new file
-add the 10th line, which is the new one
-delete the old file, and save the new file with the same name.
This has the problem of being cumbersome, slow, not efficient. In Shell scripting I could do it easily, but since I use python, I hoped for a simpler way to do this