Property for changing an object-attribute in an object
0
I need to call a method, when a attribute of an object within an object is changed. So I went with properties but without success. I used properties to check if the object within the object is changing. But that only calls the setter if I assign a new or existing object of that type and not when I change attribute within. class Position: def __init__(self): self.x = 0 self.y = 0 class Player: def __init__(self, x, y): self.__position = Position() self.__position.x = x self.__position.y = y @property def position(self): return self.__position @position.setter def position(self, value): print('Position changed') self.__position = value player = Player(5, 10) player.position = Position() # Setter