'How to decorate a list with deleter
I am creating decorator to a list to set, get, and delete values. But the deleter decorator is working. when I call del object[key], it doesn't actually do what I expect (print('dellllllll')).
class ListProperty:
def __init__(self) -> None:
self._l = []
@property
def l(self):
return self._l
@l.setter
def l(self, value):
self._l.append(value)
print('settttttttt')
@l.deleter
def l(self, key):
del self._l[key]
print('dellllllll')
ob = ListProperty()
print(ob.l)
ob.l = 5
print(ob.l)
ob.l = 100
print(ob.l)
del ob.l[0]
print(ob.l)
What am I missing in calling del
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
