I am looking for a way to not repeat definitions for getters/setters that are structurally the same using the @property decorator. An Example:
class foo:
def __init__(self,length):
self.length=length
# length
@property
def length(self):
return self._length
@length.setter
def length(self, val):
# do some checks here (e.g. for units, etc.) (same as in the class below)
self._length = val
class bar:
def __init__(self,width):
self.width=width
# width
@property
def width(self):
return self._width
@width.setter
def width(self, val):
# do some checks here (e.g. for units, etc.)(same as in the class above)
self._width = val
The attributes width in class bar and length in class foo have structurally the same setters so I want to define a generic setter I can apply for these attributes. However, I am not sure how to achieve the desired behaviour? Maybe with second degree decorators?
Help is greatly appreciated :)