Skip to content
Snippets Groups Projects
Commit c8611bca authored by Wissam Benadjaoud's avatar Wissam Benadjaoud
Browse files

save file

parent 2d3768fc
No related branches found
No related tags found
No related merge requests found
......@@ -23,26 +23,19 @@ class Savable:
"""
return self.amas
def save(self, file= None) -> None:
def save(self, file="filename.pickle") -> None:
"""
Save the current state of the system
"""
if file == None:
with open('filename.pickle', 'wb') as handle:
pickle.dump(self.amas, handle, protocol=pickle.HIGHEST_PROTOCOL)
else:
with open('file.pickle', 'wb') as handle:
with open(file, 'wb') as handle:
pickle.dump(self.amas, handle, protocol=pickle.HIGHEST_PROTOCOL)
@classmethod
def load(cls, file= None) -> 'Savable':
def load(cls, file="filename.pickle") -> 'Savable':
"""
Load the last save of the system
"""
if file == None:
with open('filename.pickle', 'rb') as handle:
amas_object = pickle.load(handle)
else:
with open('file.pickle', 'rb') as handle:
amas_object = pickle.load(handle)
with open(file, 'rb') as handle:
amas_object = pickle.load(handle)
return cls(amas_object)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment