-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserialize.py
More file actions
26 lines (24 loc) · 910 Bytes
/
serialize.py
File metadata and controls
26 lines (24 loc) · 910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class DictionarySerializer:
def __init__(self,path):
self.dictionary = {}
self.path = path
def load_from_file(self):
try:
with open(self.path, 'r') as file:
self.dictionary = eval(file.read())
print("Dictionary loaded successfully!")
except FileNotFoundError:
print("File not found!")
except Exception as e:
print(f"Error occurred while loading dictionary: {e}")
def save_to_file(self):
try:
with open(self.path, 'w') as file:
file.write(str(self.dictionary))
print("Dictionary saved successfully!")
except Exception as e:
print(f"Error occurred while saving dictionary: {e}")
def add(self, key, value):
self.dictionary[key] = value
def return_move(self, key):
return self.dictionary[key]