Python version of statechart