中断if-else循环而不中断while循环

2024-06-16 11:37:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用Python编写一个程序,我需要在不中断while循环的情况下中断if-else-lop

当前代码(例如,不完整的代码。不是完整的代码):

class foo:
  def __init__(self, time1, link)
        while self.isItNow == False:
            self.current_time = self.now.strftime("%H:%M")
            print(self.current_time)
            if str(self.current_time) == self.time1:
                webbrowser.open(self.link, new=1)
                self.isItNow = True
            else:
                print("Current Time =", self.current_time,". Retrying again in 5 seconds")
                time.sleep(5)
                break

我想中断else并再次启动if循环,但我不能这样做,因为它中断了while循环

提前感谢


Tags: 代码self程序iftimelink情况current