From 2d3768fc8491de527b022f2b7e25dd34f6f6a93d Mon Sep 17 00:00:00 2001 From: Wissam Benadjaoud <benadjaoud.wissam@gmail.com> Date: Thu, 20 May 2021 23:31:05 +0200 Subject: [PATCH] add specific file --- pyAmakCore/classes/scheduler_tool/savable.py | 23 +++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/pyAmakCore/classes/scheduler_tool/savable.py b/pyAmakCore/classes/scheduler_tool/savable.py index fcffd31..d7f1913 100644 --- a/pyAmakCore/classes/scheduler_tool/savable.py +++ b/pyAmakCore/classes/scheduler_tool/savable.py @@ -23,19 +23,26 @@ class Savable: """ return self.amas - def save(self) -> None: + def save(self, file= None) -> None: """ Save the current state of the system """ - with open('filename.pickle', 'wb') as handle: - pickle.dump(self.amas, handle, protocol=pickle.HIGHEST_PROTOCOL) + 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: + pickle.dump(self.amas, handle, protocol=pickle.HIGHEST_PROTOCOL) @classmethod - def load(cls) -> 'Savable': + def load(cls, file= None) -> 'Savable': """ Load the last save of the system """ - with open('filename.pickle', 'rb') as handle: - amas_object = pickle.load(handle) - - return cls(amas_object) \ No newline at end of file + 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) + return cls(amas_object) -- GitLab