When i try to update my json file i get a error
Question:
When i try to update my json file i get this error:AttributeError: module ‘json’ has no attribute ‘update’ and I don’t understand why here is my code:
` with open(file="data.json", mode="r") as data_file:
data = json.load(data_file)
json.update(new_data)
with open(file="data.json", mode="w") as data_file:
json.dump(data, data_file, indent=4)
website.delete(0, t.END)
password.delete(0, t.END)`
Answers:
Replacing the third line (json.update(new_data)
) with data.update(new_data)
should fix your issue, assuming new_data
is a dict.
The update is on the script "json" that is not a correct reference, replace it with "data.update"
When i try to update my json file i get this error:AttributeError: module ‘json’ has no attribute ‘update’ and I don’t understand why here is my code:
` with open(file="data.json", mode="r") as data_file:
data = json.load(data_file)
json.update(new_data)
with open(file="data.json", mode="w") as data_file:
json.dump(data, data_file, indent=4)
website.delete(0, t.END)
password.delete(0, t.END)`
Replacing the third line (json.update(new_data)
) with data.update(new_data)
should fix your issue, assuming new_data
is a dict.
The update is on the script "json" that is not a correct reference, replace it with "data.update"