Oct-14-2023, 11:58 AM
ok so basically im trying to build a workout tracker app. my problem is i want to check if there is already the date inside the json fille so it won't overwrite it and if it is there then i want to append to the list in the element of the dictionary. so for example if there is already workout data for saturday the 14th of october i will append to the list of the activities (in this case there was already cycling ) and i want to append to that list to add aerobics for example. here is my relevant code
ONE LAST NOTE: i am iterating through the list of dictionaries that contain the entry information which is why entry is present in my code. it is the assigned name for each of the dictionaries inside the list
if messagebox.askokcancel(title=f"{entry['day']} Workout Information",message=f"Activity: {entry['activity']} for {entry['unit']} minutes.\nSave this activity?"): if entry["day"] in saved_data: saved_data[entry["day"]['activity']].append(entry['activity']) saved_data[entry["day"]['unit']].append(entry['unit']) else: new_data={entry['day']:{"activity":[entry['activity']],"unit":[entry['unit']]}} saved_data.update(new_data) else: if messagebox.askokcancel(title=f"{entry['day']} Workout Information",message=f"Activity: {entry['activity']} for {entry['unit']} minutes.\nSave this activity?"): new_data={entry['day']:{"activity":entry['activity'],"unit":entry['unit']}} saved_data.update(new_data)saved data represents the json file contents. as i have a button to generate columns of entries and labels i had to create a list of the activities that contain the day,activity and duration of the workout. the error that i get is a 'TypeError: string indices must be integers, not 'str on line 3 after the second if statement
ONE LAST NOTE: i am iterating through the list of dictionaries that contain the entry information which is why entry is present in my code. it is the assigned name for each of the dictionaries inside the list