Oct-14-2023, 03:37 PM
(This post was last modified: Oct-14-2023, 03:40 PM by deanhystad.)
Post entire error message, including the error trace. Post all relevant code, preferably a runnable example.
Without any error information I don't know if the problem is that "entry" is a list, but my guess is the error is here:
To save in a json file, entry["activity"] and entry["unit"] must be serializable. If they are mutable (dictionaries or lists) you need to put a copy of the object in saved_data, possibly a deep copy.
Without any error information I don't know if the problem is that "entry" is a list, but my guess is the error is here:
saved_data[entry["day"]['activity']].append(entry['activity'])What is entry["day"]? Is it a date string? You are treating it as a dictionary, trying to get "activity". It should probably be this:
saved_data[entry["day"]]['activity'].append(entry['activity'])That is not the only problem. Do you want an "activity" associated with a "unit". Your code just makes a bunch "activity" dictionaries and a bunch of "unit" dictionaries. There is no connection between them. I think you want to do this:
if messagebox.askokcancel(blah blah blah): saved_data.get[entry["day"], []).append({"activity": entry["activity], "unit": entry["unit"])This uses dictionary.get(key, default) to return a new list when entry["day"] is not in saved_data.
To save in a json file, entry["activity"] and entry["unit"] must be serializable. If they are mutable (dictionaries or lists) you need to put a copy of the object in saved_data, possibly a deep copy.