Пишу код (Python 3.6.0):
class Name: # name descriptor def __init__(self): self.value = 'default name' def __get__(self, instance, owner): return self.value def __set__(self, instance, value): self.value = value def __delete__(self, instance): raise AttributeError('from Name.__delete__') class SomeClass: myName = Name() #--------------------------------------------------------------------------------- if __name__ == '__main__': a = SomeClass() b = SomeClass() print(a.myName) print(b.myName) a.myName = 'my name is A' print(a.myName) print(b.myName) b.myName = 'my name is B' print(a.myName) print(b.myName) del a.myName
Получаю результат:
==================== RESTART: Dweb.py/attrs/testdesc.py ==================== default name default name my name is A my name is A my name is B my name is B Traceback (most recent call last): File "D:/web.py/attrs/testdesc.py", line 36, in <module> del a.myName File "D:/web.py/attrs/testdesc.py", line 13, in __delete__ raise AttributeError('from Name.__delete__') AttributeError: from Name.__delete__ >>>
В чём ошибка?