[Tutor] My first python gotcha
dominic.fox
dominic.fox" <dominic.fox@ntlworld.com
Mon, 13 May 2002 22:39:12 +0100
Looked like this:
class FSM:
"""A finite state machine."""
def __init__(self):
self.state = ''
self.states = {}
def addState(self, name, rules=[]):
self.states[name] = rules
def addRule(self, name, rule):
self.states[name].append(rule)
def setState(self, state):
self.state = state
def receive(self, input):
for nextRule in self.states[self.state]:
result, toState = nextRule(input)
if (result == 1):
self.state = toState
break
The assignment rules=[] in addState was what got me. Every time I added a
rule, it got added to everything...
Dom
--> Nobody knows the trouble you've seen / walking from your desk to the
staff canteen <--
homepage: http://www.geocities.com/domfox