class MyClass():
def __init__(self):
self.attribute_1 = "foo"
self.attribute_2 = "bar"
@property
def attribute_1(self):
return self._attribute_1
@attribute_1.setter
def attribute_1(self,s):
self._attribute_1 = s
@property
def attribute_2(self):
return self._attribute_2
@attribute_2.setter
def attribute_2(self,s):
self._attribute_2 = s
>>> ob = MyClass()
>>> ob.attribute_1 = 'fizz' #Ok
>>> ob.atribute_1 = 'buzz' #want to throw an exception because this has no setter or @property def
I would like my class to complain if we try and set an attribute that has not been decorated with property and a setter. I have tried using slots but can't get it working with the property decorator. 'attribute' in __slots__ conflicts with class variable
Any thoughts?