Create data.py
Browse files
data.py
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
|
3 |
+
def load_data(filename="data.json"):
|
4 |
+
try:
|
5 |
+
with open(filename, "r") as f:
|
6 |
+
data = json.load(f)
|
7 |
+
except FileNotFoundError:
|
8 |
+
data = {} # Initialize an empty dictionary if no data file exists
|
9 |
+
return data
|
10 |
+
def save_data(data, filename="data.json"):
|
11 |
+
with open(filename, "w") as f:
|
12 |
+
json.dump(data, f)
|