Re: [Tutor] detecting data member changes

2007-04-24 Thread Alan Gauld
"Luke Paireepinart" <[EMAIL PROTECTED]> wrote > Is this properties method acceptable Python form or is it more > proper to > have modifying member functions like Alan said? Properties is fine and was one of the options that I suggested. However I didn't mean you should have modifying member fun

Re: [Tutor] detecting data member changes

2007-04-24 Thread Kent Johnson
Luke Paireepinart wrote: > I can see how some people might be surprised to know that changing > classinstance.leds automagically sends a communication packet to the wii > remote without their knowledge, but if they're aware of the side-effect, > it seems to be a more elegant way of doing things

Re: [Tutor] detecting data member changes

2007-04-24 Thread Luke Paireepinart
> No, the above code should work with classinstance.leds. Maybe you are > confusing __setattr__ - which affects attributes like .leds - with > __setitem__ which is used for classinstance['leds'] Ah, yes. You hit the hail on the nead there, Kent. Thanks for clarifying that for me. > >> >> Is th

Re: [Tutor] detecting data member changes

2007-04-24 Thread Kent Johnson
Luke Paireepinart wrote: >>> 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.

Re: [Tutor] detecting data member changes

2007-04-24 Thread Luke Paireepinart
> > Make leds a property: > > class wiimote(object): > def __init__(self): > self._leds = [0, 0, 0, 0] > > def _set_leds(self, leds): > self._leds = leds > self._updateLEDs() > > def _get_leds(self): > return self._leds > > leds = property(_get_leds,

Re: [Tutor] detecting data member changes

2007-04-24 Thread Kent Johnson
Luke Paireepinart wrote: > Supposing I have a class like this: > > class wiimote(object): > def __init__(self): > self.leds = [0,0,0,0] > def updateLEDs(self): > do_stuff()#write correct output report to wiimote to toggle LEDs. > > So basically what I want to do is that wh

Re: [Tutor] detecting data member changes

2007-04-24 Thread Alan Gauld
"Luke Paireepinart" <[EMAIL PROTECTED]> wrote > > class wiimote(object): >def __init__(self): >self.leds = [0,0,0,0] >def updateLEDs(self): >do_stuff()#write correct output report to wiimote to toggle > LEDs. > > So basically what I want to do is that whenever the self.leds

[Tutor] detecting data member changes

2007-04-23 Thread Luke Paireepinart
Supposing I have a class like this: class wiimote(object): def __init__(self): self.leds = [0,0,0,0] def updateLEDs(self): 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,