【发布时间】:2020-09-27 20:31:38
【问题描述】:
我正在尝试从 talk 复制代码:
class Video:
## Define the states
PLAYING = "playing"
PAUSED = "paused"
STOPPED = "stopped"
def __init__(self,source):
self.source = source
transitions = [
{"trigger":"play","source":self.PAUSED, "dest":self.PLAYING},
{"trigger":"play","source":self.STOPPED, "dest":self.PLAYING},
##
{"trigger":"pause","source":self.PAUSED, "dest":self.PAUSED},
##
{"trigger":"stop","source":self.PAUSED, "dest":self.STOPPED},
{"trigger":"stop","source":self.PLAYING, "dest":self.STOPPED}
]
self.machine = Machine(
model = self,
transitions = transitions,
initial = self.STOPPED)
def pause(self):
print ("pause")
def play(self):
print ("play")
def stop(self):
print ("stop")
但我称之为,它不起作用:
test = Video("some text")
返回警告:
2020-09-27 17:25:50,255 [11472] WARNING transitions.core:828: [JupyterRequire] Model already contains an attribute 'play'. Skip binding.
2020-09-27 17:25:50,259 [11472] WARNING transitions.core:828: [JupyterRequire] Model already contains an attribute 'pause'. Skip binding.
2020-09-27 17:25:50,260 [11472] WARNING transitions.core:828: [JupyterRequire] Model already contains an attribute 'stop'. Skip binding.
但主要问题是状态没有改变:
这是原演讲的代码:
【问题讨论】: