Python How can i use buffer
<p>I have to solve this question :</p>

<p>We have a text file like this :</p>

<pre><code>"imei": "123456789",
"sim_no": "+90 xxx xxx xx xx",
"device_type": "standart",
"hw_version": "1.01",
"sw_version": "1.02"
</code></pre>

<p>And we should read this JSON data, then we should read this data each 1 min and put to buffer(idk how can i put, is buffer array or dict?) then we should delete the oldest file each 5 min. Exceptions are important. Format sould be like "imei", "hw_version", "sw_version", "device_type". We sould solve buffer overflowing.</p>

<p>I write this code :</p>

<pre><code>import json
from time import sleep

def buffer(data):
    pass
    #imei = data.get("imei") # I want to read like this
    # this function should put the variables to array
counter=0
while True:
    with open("config.txt") as f:
        mydict = json.loads('{{ {} }}'.format(f.read()))    
    buffer(mydict)
    sleep(60)
    counter+=1
    if counter%5==0
        # delete the oldest data
</code></pre>

<p>How can i use buffer? And how can i continue this code?</p>

<p>What you want are the last 5 values, so you should just append the new one to a list and if it is bigger than 5, delete the first one.</p>

<pre><code>my_list.append(my_dict)
if len(my_list) &gt; 5:
    my_list.pop(0)
</code></pre>

<p>So, after that you just sleep for 60 seconds and nothing else</p>

python arrays python-3.x