60. Persistence with JSON
Tasks should persist between runs. Use the json module for storage.
Saving Tasks
import json
def save_tasks(filename="tasks.json"):
with open(filename, "w") as f:
json.dump(tasks, f)
Loading Tasks
def load_tasks(filename="tasks.json"):
global tasks
try:
with open(filename) as f:
tasks = json.load(f)
except FileNotFoundError:
tasks = []
Wrap-Up
JSON storage makes the Task Manager persistent and portable.