How can I pass a dictionary path as an argument? I thought maybe it had something to do with *args or **kwargs but I didn't understand how to use them for this
dictionary = {
'key1': {
'attribute1': 'green',
},
'attribute2': 5
}
def SaveToFile(target, value):
with open('savefile.json', 'r') as savefile:
dictionary = json.load(savefile)
dictionary[target] = value
with open('savefile.json', 'w') as savefile:
json.dump(dictionary, savefile)
SaveToFile('["key1"]["attribute1"]', 'blue')
SaveToFile('["attribute2"]', 10)
print(dictionary)
desired output:
{
'key1': {
'attribute1': 'blue'
},
'attribute2': 10
}
ChangeValue(dictionary["key1"]["attribute1"], 'blue')and set that target equal to value?