"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
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
> 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
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.
>
> 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,
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
"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
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,