Answer the question
In order to leave comments, you need to log in
Python json why is it throwing an error?
python file:
import json
with open('test.json', 'r') as f:
data = json.load(f)
for items in data:
items["1"] += [1, 2]
with open('test.json', 'w') as f:
json.dump(data, f, indent=3)
[
{
"1": []
},
{
"2": []
}
]
items["1"] += [1, 2]
KeyError: '1'
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question