Show Menu
Cheatography

Python Automat Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Basic

@machi­ne.s­tate()
Define a state (use
initia­l=True
to set initial state)
@machi­ne.i­nput()
Define input. Body must be empty
@machi­ne.o­ut­put()
Define output. Make processing here
To define transi­tions:
state.u­po­n(i­nput, enter=­nex­t_s­tate, outputs=[]

Graphviz

The
Method­ica­lMa­chine
class has an function named
asDigr­aph()


You can use it to create a
Digraph
object from the
graphviz
package. Then you can manipulate it as any Digraph from graphviz.

To render it, you can use
Digrap­h.r­end­er(­fil­ename)


For example:
g = _machi­ne.a­sD­igr­aph()

g.rend­er(­"­_ma­chi­ne.g­v")
 

Serial­izing

You can serialize the Machine. To do that, you must define serialized values for each state:
@machi­ne.s­ta­te(­ser­ial­ize­d="o­n")


Then you define a serializer function which will receive this state serialized value:
@machi­ne.s­er­ial­izer()

def save(self, state):

    return {"is­-it­-on­": state}


Then the unseri­alizer:
@machi­ne.u­ns­eri­ali­zer()

def _resto­re(­self, blob):

    return blob["i­s-i­t-o­n"]