Decorating a class to monitor attribute changes
问题 I want to have classes that automatically send notifications to subscribers whenever one of their attributes change. So if I would write this code: @ChangeMonitor class ChangingClass(object): def __init__(self, x): self.x = x changer = ChangingClass(5) print("Going to change x.") changer.x = 6 print("Going to not change x.") changer.x = 6 print("End of program") The output would be: Going to change x Old x = 5, new x = 6 Going to not change x. End of program. My question is how to implement