所以我正在尝试学习跳跃运动 SDK并在 4-5 年内不接触它后重新学习 python,我在 python 2.7 中遇到了生成器的问题
基本上我有一个单词列表,每次跳跃动作选择一个新的“圆圈”手势时,我想打印列表中的下一个单词。我所看到的是,每次on_frame
回调触发时,只打印列表中的第一个单词。我相信正在发生的事情是 python 运行时忘记了事件之间生成器的状态。有没有办法在手势事件之间保持生成器状态?
if not frame.hands.is_empty:
for gesture in frame.gestures():
if gesture.type == Leap.Gesture.TYPE_CIRCLE:
circle = CircleGesture(gesture)
# Determine clock direction using the angle between the pointable and the circle normal
action = None
if circle.pointable.direction.angle_to(circle.normal) <= Leap.PI/4:
action = GestureActions.clockwiseCircleGesture()
else:
action = GestureActions.counterClockwiseCircleGesture()
print action.next()
def clockwiseCircleGesture():
words = ["You", "spin", "me", "right", "round", "baby", "right", "round", "like", "a", "record", "baby", "Right", "round", "round", "round", "You", "spin", "me", "right", "round", "baby", "Right", "round", "like", "a",
"record", "baby", "Right", "round", "round", "round"]
for word in words:
yield word
对此的任何见解都会很棒。谢谢