Created
March 25, 2019 01:01
-
-
Save TheBeege/1d9a158dd04f590f30f0b243f7fbd027 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
# Notice that we've added data as a parameter to our write_data function | |
def write_data(data, file_path='meals.json'): | |
with open(file_path, 'w', newline='') as f: | |
json.dump(data, f) | |
def read_data(file_path='meals.json'): | |
with open(file_path) as f: | |
new_data = json.load(f) | |
return new_data | |
# Read the data from our file into a variable | |
meal_data = read_data() | |
# Add new data. However you usually do it, put here | |
meal_data['dessert'] = 5 | |
# Write the updated data back to the file | |
write_data(meal_data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment