我有一个功能:
def turn(self, keyEvent):
if (keyEvent.key == pygame.locals.K_UP) and \
(self.body[0].direction != Directions.DOWN):
self._pivotPoints.append(PivotPoint(self.body[0].location, \
Directions.UP))
print("Placing pivot point up")
#elif chain for the down left and right button presses omitted
#code is the same for each input
创建以下类的实例:
class PivotPoint:
def __init__(self, location, \
direction):
"""When a body part reaches a pivot point, it changes directions"""
pdb.set_trace()
self.location = location
self.direction = direction
当我运行这段代码时,pdb 启动,我得到以下 I/O 序列:
> /home/ryan/Snake/snake.py(50)__init__()
-> self.location = location
(Pdb) step
> /home/ryan/Snake/snake.py(51)__init__()
-> self.direction = direction
(Pdb) step
--Return--
> /home/ryan/Snake/snake.py(51)__init__()->None
-> self.direction = direction
(Pdb) step
> /home/ryan/Snake/snake.py(89)turn()
-> print("Placing pivot point right")
第 51 行的语句被执行了两次。为什么会这样?