Update page 'Day 5 Homework - Karen'

2023-04-07 01:59:43 +02:00
parent 2cb4a90f44
commit 55f1fc0f7a
+8 -7
@@ -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: