2023-04-13 15:45:21 -04:00
|
|
|
'''
|
2023-04-13 15:38:06 -04:00
|
|
|
class Vault:
|
|
|
|
|
def __init__(self):
|
|
|
|
|
self._treasure = "gold"
|
|
|
|
|
self._attributes = dict(self.__dict__)
|
|
|
|
|
|
|
|
|
|
def __setattr__(self, name, value):
|
|
|
|
|
if name != "_attributes" and name not in self._attributes:
|
|
|
|
|
print("attribute deleted!")
|
|
|
|
|
self._attributes[name] = value
|
|
|
|
|
super().__setattr__("_attributes", dict(self.__dict__))
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def treasure(self):
|
|
|
|
|
if self.__dict__ != self._attributes:
|
|
|
|
|
print("attribute deleted!")
|
|
|
|
|
return self._treasure
|
2023-04-13 15:45:21 -04:00
|
|
|
|
|
|
|
|
v=Vault()
|
|
|
|
|
print(v.treasure)
|
|
|
|
|
'''
|
|
|
|
|
'''
|
|
|
|
|
class Vault:
|
|
|
|
|
def __init__(self):
|
|
|
|
|
self._treasure = "gold"
|
|
|
|
|
self._original_dict = dict(self.__dict__)
|
|
|
|
|
|
|
|
|
|
def __setattr__(self, name, value):
|
|
|
|
|
if name != "_treasure" and name in self.__dict__ and self._original_dict.get(name) != value:
|
|
|
|
|
print("attribute deleted!")
|
|
|
|
|
self.__dict__[name] = value
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def treasure(self):
|
|
|
|
|
if self.__dict__ != self._original_dict:
|
|
|
|
|
print("attribute deleted!")
|
|
|
|
|
return self._treasure
|
|
|
|
|
v = Vault()
|
|
|
|
|
print(v.treasure)
|
|
|
|
|
'''
|
|
|
|
|
'''
|
|
|
|
|
class Vault:
|
|
|
|
|
def __init__(self):
|
|
|
|
|
self._treasure = "gold"
|
|
|
|
|
self._attributes = dict(self.__dict__)
|
|
|
|
|
|
|
|
|
|
def __setattr__(self, name, value):
|
|
|
|
|
if name != "_attributes" and name not in self._attributes:
|
|
|
|
|
print("attribute deleted!")
|
|
|
|
|
self._attributes[name] = value
|
|
|
|
|
super().__setattr__("_attributes", dict(self.__dict__))
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def treasure(self):
|
|
|
|
|
if self.__dict__ != self._attributes:
|
|
|
|
|
print("attribute deleted!")
|
|
|
|
|
return self._treasure
|
|
|
|
|
|
|
|
|
|
v = Vault()
|
|
|
|
|
print(v.treasure)
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
class Vault:
|
|
|
|
|
def __init__(self):
|
|
|
|
|
self._treasure = "gold"
|
|
|
|
|
|
|
|
|
|
def __setattr__(self, name, value):
|
|
|
|
|
if name != "_attributes" and name not in self.__dict__:
|
|
|
|
|
print("attribute deleted!")
|
|
|
|
|
self.__dict__[name] = value
|
|
|
|
|
self._attributes = dict(self.__dict__)
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def treasure(self):
|
|
|
|
|
if self.__dict__ != self._attributes:
|
|
|
|
|
print("attribute deleted!")
|
|
|
|
|
return self._treasure
|
|
|
|
|
|
|
|
|
|
v = Vault()
|
|
|
|
|
print(v.treasure)
|
|
|
|
|
|