Answer the question
In order to leave comments, you need to log in
How to get rid of recursion in __settatr__ method?
How to correctly assign an attribute to an object in the __setattr__(instead of print('DONE')) method of a derived class so that there is no recursion?
class Calendar:
__slots__ = ('D', 'M', 'Y')
def __init__(self, d = 0, m = 0, y = 0):
self.D = d
self.M = m
self.Y = y
print(self)
def __setattr__(self, key, value):
if isinstance(value, int):
print('ГОТОВО')
else:
raise AttributeError
def __getattr__(self, item):
print('ГОТОВО2')
c = Calendar(1, 12, 2004)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question