class Editable: def make_copy(self): # makes an internal copy of self # delete old copy if hasattr(self, "_copy"): if self._copy is not None: self._copy = None # make new copy self._copy = JSON.parse(JSON.stringify(self)) def copy(self): # return internal copy of self # check if even initialized if hasattr(self, "_copy"): return self._copy else: return None def overwrite_with_copy(self): for key, value in dict(self._copy).items(): if key == "_copy": continue setattr(self, key, value) self._copy = None