I came across the following problem, the code example below is returning a curly bracket too much every second call:
import json as js
def switchState(path, type):
file = open(path + '/states.txt', 'r+')
json = js.loads(file.read())
json[type] = not json[type]
file.seek(0)
js.dump(json, file)
file.close()
in whereas the data json has the form
{"sim": true, "pip": false}
, and calling
switchState('path','sim')
once, leads to
{"sim": false, "pip": false}
but calling it a second time it leads to:
{"sim": true, "pip": false}}
anyone has an idea whats the reason for this? thanks in advance