I want to implement a class property that is computed from other properties.
class Sum(object):
@property
def a(self):
return self._a
@a.setter
def a(self, val):
self._a = a
self._constructSeries()
@property
def b(self):
return self._b
@b.setter
def b(self, val):
self._b = b
self._constructSeries()
def _constructSeries(self):
# Some calculations involving a and b
self._series = function(a, b)
def __init__(self, a, b):
self.a = a
self.b = b
One way I know of is to define series as a property
@property
def series(self):
return fun(a,b)
But I want to avoid calling fun each and every time as it takes a lot of computations. What is the standard way to handle such a case?