Python: 在任意点中断循环

Python: break loop at any point

我在 Raspberry Pi 2 上有一个 python 脚本,我想在任何时候打破循环 buttonpressed=True

所以像这样:

while True:
    try:
        do_something_pythonic()
    except buttonpressed=True:
        break
    while not self.button_pressed:
         do_pythonic()

...
def OnButtonPress(self,evt):
    self.button_pressed = True