I want to change the value of a nested key but I get this error
key['score'] = new_score # come back to this
TypeError: 'str' object does not support item assignment
Here is my code:
def add_score(self, obj):
for child in reversed(self.root.screen_two.ids.streak_zone.children):
name = child.text
with open("streak.json", "r+") as read_file:
data = json.load(read_file)
for key in data.keys():
if key == name:
score = data.get(key, {}).get('score')
new_score = score + 1
key['score'] = new_score # come back to this
This is what my json file looks like:
{"one": {"action": "one",
"delay": 1557963534.4314187,
"seconds": 60,
"score": 0,
"delta": 1557963474.4314187},
"two": {"action": "two",
"delay": 1557963664.037102,
"seconds": 120,
"score": 0,
"delta": 1557963544.037102},
"three":{"action": "three",
"delay": 1557963792.4683638,
"seconds": 180,
"score": 0,
"delta": 1557963612.4683638}
}
How would I change the score
value inside of my json file?