I need a python script implementing a circular buffer for rows in a text file limited to N rows like this:
row 1 -> pop
row 2
row 3
|
|
push -> row N
What's the best solution?
EDIT: This script should create and maintain the text file which only contains the latest N lines. Then it should pop the first line pushed in. Like a fifo buffer.
Use
collections.deque
. It supports amaxlen
parameter.Try my recipe and sorry for italian usage: