from transitions import Machine
class Matter(object):
pass
lump = Matter()
# 状态定义
states=['solid', 'liquid', 'gas', 'plasma']
# 初始化状态机
machine = Machine(model=lump, states=states, initial='solid')
# 添加转换
machine.add_transition(trigger='melt', source='solid', dest='liquid')
machine.add_transition(trigger='evaporate', source='liquid', dest='gas')
machine.add_transition(trigger='ionize', source='gas', dest='plasma')
# 状态转换
lump.melt()
print(lump.state) # 输出: liquid