This way you can choose which state you need to be in to trigger the transition, what the trigger is, as well as the destination and functions to run after the transition is done. So to use this transition, we need to be in the relaxing state, and we need a function work_out_session.

Testing the State Machine

To test the state machine, you can run this code:

from <The filename of the file where you created WorkOut> import WorkOut
#create object of the Workout State machine
wo = WorkOut()
#Check which state the state machine starts in.
print "The first state in the state machine is: %s" % wo.state
#Start to work out/Change State.
wo.go_work_out();
print "Done working out, in state: %s \nYou have worked out %s times." % (wo.state, str(wo.work_out_times))
#Now you can keep working out as much as you want:
for i in range(0, 5):
wo.go_work_out();
print "Done working out, in state: %s \nYou have worked out %s times." % (wo.state, str(wo.work_out_times))

In this script, you can see that you call a transition by triggering the name of the state machine instance.