[Tutor] detecting data member changes
rabidpoobear at gmail.com
Tue Apr 24 08:42:14 CEST 2007
Supposing I have a class like this:
self.leds = [0,0,0,0]
do_stuff()#write correct output report to wiimote to toggle LEDs.
So basically what I want to do is that whenever the self.leds variable
is changed, the updateLEDs method is called.
( I can't call it constantly in a loop because 1) the wii remote freaks
out, and 2) that seems pretty ineffiicent.)
I know I could use a __setattr__ but then I'd have to access the leds
using a dictionary with an 'LED' key mapped to the status array.
It's not necessarily a bad thing for my own use, but it seems like it'd
be off-putting to other people using my library.
So is there a way to detect such changes that's Pythonic?
More information about the Tutor