La solution
01: import pickle
02:
03:
04: class Originator:
05: def restore(self, memento):
06: previous_state = pickle.loads(memento)
07: vars(self).clear()
08: vars(self).update(previous_state)
09:
10: def save(self):
11: return pickle.dumps(vars(self))
12:
13: def __str__(self):
14: chain = 'Liste des attributs\n'
15: attributes = vars(self)
16: for name in attributes:
17: chain += ' - {} : {}\n'.format(name, attributes)
18: return chain
19:
20:
21: class MyOriginator(Originator):
22: def __init__(self, value):
23: super().__init__()
24: ...
- Accédez à tous les contenus de Connect en illimité
- Découvrez des listes de lecture et des contenus Premium
- Consultez les nouveaux articles en avant-première