diff --git a/Day 5 Homework - Karen.md b/Day 5 Homework - Karen.md index acb4eb2..277d589 100644 --- a/Day 5 Homework - Karen.md +++ b/Day 5 Homework - Karen.md @@ -4,19 +4,20 @@ class Vault: def __init__(self): self._treasure = "gold" - self._attributes = dict(self.__dict__) - + self._original_dict = dict(self.__dict__) + def __setattr__(self, name, value): - if name != "_attributes" and name not in self._attributes: + if name != "_treasure" and name in self.__dict__ and self._original_dict.get(name) != value: print("attribute deleted!") - self._attributes[name] = value - super().__setattr__("_attributes", dict(self.__dict__)) - + self.__dict__[name] = value + @property def treasure(self): - if self.__dict__ != self._attributes: + if self.__dict__ != self._original_dict: print("attribute deleted!") return self._treasure +v = Vault() +print(v.treasure) ``` To assess other's Vault (although it may not be ethical), we can use `__getattribute__` method like: