State Machines in Python

D'Arcy J.M. Cain darcy at
Sat Sep 4 20:30:22 CEST 2010

On Sat, 04 Sep 2010 13:58:00 -0400
Roy Smith <roy at> wrote:
> > while True:
> >     state = state(data)
> This is the pattern I've always used.  Simple and effective for any 
> state machine which is small enough to code by hand.  I generally have 
> my state methods return (next_state, output) tuples, but that's a detail.

What is "output" for?  Is it a string or something else?  What do you
do with it?  Notice that I create a dictionary which is passed around
so that states can pass whatever information back that they deem useful
and any state can pick up whatever info it needs.  for example, in my
sample code every state uses the counter but only two states use the
flag element.

D'Arcy J.M. Cain <darcy at>         |  Democracy is three wolves                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.

More information about the Python-list mailing list