Let's consider the following example:
class SubClass:
def __init__(self):
self._param = None
@property
def param(self):
print('read param')
return self._param
@param.setter
def param(self, value):
print('set param')
self._param = value
class MainClass:
def __init__(self):
self._var = SubClass()
@property
def var(self):
print('read var')
return self._var
@var.setter
def var(self, value):
print('set var')
self._var = value
If I do:
cls = MainClass()
cls.var.param = 3
I obtain:
'read var'
'set param'
How can I make MainClass
aware that var.param
has changed?
Useful additional info: consider that in my actual code param
is not a scalar but an array with hundreds of elements, so I would like to avoid to create a copy and then just compare them. Moreover, param
and var
are not the only properties.