In case you want to change other variables in a class on change
of an attribute you simply just write a property
for it. That works fine, if you have a simple data type. But if your variable contains a complex type like a list (not so untypical), the content itself can be changed without calling the variable.setter
again.
Are there any callbacks or events that can be used to track changes to a list attribute of a class? What else can be done to keep the code clean and not destroy the inner functionality of the class?
Example:
class Accumulator(object)
def __init__(self,all_things):
# :param all_things: a list of stuff of any kind
self.__all_things = all_things
@property
def all_things(self):
return self.__all_things
@all_things.setter
def all_things(self,input):
self.__all_things = input
Thinking outside the box is probably the solution. The priority is not to keep the class structure alive, but to find a pattern that works and allows a clean API!