> IMHO ... untested
>
> class LightBulb:
> def __init__(self, on=False): self.IsOn = on
>
> def turnOn(self): self.switchIt(True)
> def turnOff(self):self.switchIt(False)
>
> def switchIt(self, turnon):
> if self.isOn==turnon: print "The Switch is Already %s
On Jun 21, 12:22 am, Bruno Desthuilliers wrote:
> [EMAIL PROTECTED] a écrit :
> (snip)
>
> >>> I would like to be able to get a good hold of the concept
> >> state machines ?
>
> > Well both state machines and classes (objects). That may be a bit of a
> > tall order to take on all at once but the
[EMAIL PROTECTED] a écrit :
(snip)
>>> I would like to be able to get a good hold of the concept
>> state machines ?
>
> Well both state machines and classes (objects). That may be a bit of a
> tall order to take on all at once but the concepts seem to be quite
> related.
They are, since OO was
> I've written code that looks a lot like that, and it's
> a perfectly acceptable pattern IMHO. I don't bother
> with the variables ON and OFF, though, as they add no
> clarity to simply using 'ON' and 'OFF' for the states.
>
> [...]
> The test portion of the code is actually longer than
> the cl
[EMAIL PROTECTED] a écrit :
> Greetings,
>
> I have been working on a little project today to help me better
> understand classes in Python (I really like Python). I am a self
> taught programmer and consider myself to fall in the "beginner"
> category for sure. It was initially sparked by reading
--- [EMAIL PROTECTED] wrote:
>
> ON = "ON"
> OFF = "OFF"
>
> class LightBulb:
> def __init__(self, initial_state):
> self.state = initial_state
>
> def TurnOn(self):
> if self.state == OFF:
> self.state = ON
> else:
> print "The Bulb Is A
Thank you both for the insightful responses(I knew I came to the right
place)!
Steven -- The original inspiration was a "State Machine" your code re-
write was what I was trying to accomplish but quickly got in way over
my head. Thank you for expanding on that aspect of it. That will give
me some
En Tue, 19 Jun 2007 22:34:27 -0300, <[EMAIL PROTECTED]> escribió:
> I have been working on a little project today to help me better
> understand classes in Python (I really like Python). I am a self
> taught programmer and consider myself to fall in the "beginner"
> category for sure. It was initi
On Jun 19, 6:34 pm, [EMAIL PROTECTED] wrote:
> Greetings,
>
> I have been working on a little project today to help me better
> understand classes in Python (I really like Python). I am a self
> taught programmer and consider myself to fall in the "beginner"
> category for sure. It was initially sp