【问题标题】:Function does not enter the loop函数不进入循环
【发布时间】:2022-06-28 22:26:30
【问题描述】:
def ConsultaDownload():
    VF = False
    VR = False
    consultar = pyautogui.locateOnScreen('ConsultaRetorno.PNG')
    pyautogui.click(consultar)
    sleep(0.5)
    while VF and VR == False:
        print(1)
        sleep(30)
        pyautogui.click(consultar)
        sleep(0.5)
        finalizado = pyautogui.locateOnScreen('Processamento_Finalizado.PNG')
        fRegistro = pyautogui.locateOnScreen('')  # processado e sem registro
        if finalizado:
            VF = True

        elif fRegistro:
            VR = True


ConsultaDownload()

在我的代码中的某个时刻,我求解了 print(1) 以查看循环重复了多少次,我意识到实际上它甚至不想进入循环。我不知道如何解决这个问题,谁能帮帮我?

【问题讨论】:

  • VF 为假。它不会进入循环。你的意思是while not VF and not VR:
  • 仅供参考:VF and VR == False 被解析为(VF) and (VR == False)
  • 或者不明白快捷方式的人:while (VF == True) and (VR == False):
  • while not (VF or VR)

标签: python while-loop


【解决方案1】:

我认为您对while 条件的理解在这里是不正确的。我假设你的意思是只要 VF 和 VR 都为假就循环,但在你的条件下,你只检查 VR 是否为假。 为了确保 VF 和 VR 都是假的,你应该这样做:

while not VF and not VR:

while VF and VR == False 表示当 VF 为 truthy 且 VR == False 时

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-21
    • 2011-08-18
    • 1970-01-01
    • 2015-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多