Skip to content

Instantly share code, notes, and snippets.

@TheBeege
Created March 25, 2019 01:01
Show Gist options
  • Save TheBeege/1d9a158dd04f590f30f0b243f7fbd027 to your computer and use it in GitHub Desktop.
Save TheBeege/1d9a158dd04f590f30f0b243f7fbd027 to your computer and use it in GitHub Desktop.
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