i have a python class in which i have few arguments sent to constructor as below.
class Test(object):
def __init__(self, a, b):
self.a = a
if b<10:
self.a = a*2
I know that, constructors are just meant to initialize variable's and there should be no logic inside a constructor. But, if not this way, how can i set value of "a" variable based a logic with "b" variable. I tried to use property. following is my code
class Test(object):
def __init__(self, a, b):
self.a = a
self.b = b
@property
def a(self):
self._a
@a.setter
def a(self, value):
if self.b < 10:
self._a = value*2
else:
self._a = value
But, problem is that, setter is not called when initializing with a constructor. So, how can i solve this problem of modifying the default setting of few variable inside a constructor