为什么“bool”对象不可调用?

问题描述

所以,我正在尝试使用 Python 创建一个脚本来自动打开在线课程。 这是我的代码

import webbrowser
import datetime
import time

Now = time.strftime("%D,%H:%M")

lesson1 = "03/09/21,14:10"
lesson2 = "03/10/21,14:11"
lesson3 = "03/10/21,14:12"

while True (Now != lesson1 and Now != lesson2 and Now != lesson3):
    print ("Waiting,the current time is " + Now)
    Now = time.strftime("%D,%H:%M")
    time.sleep(1)
    if (Now == lesson1):
        print ("LESSON IS opening :D")
        webbrowser.open("https://google.com")
        while (Now != "12:00"):
            time.sleep()

    if (Now == lesson2):
        print ("LESSON IS opening :D")
        webbrowser.open("https://google.com")

    if (Now == lesson3):
        print ("LESSON IS opening :D")
        webbrowser.open("https://google.com")

当我尝试运行脚本时,我收到以下消息:

Traceback (most recent call last):
  File "/home/matteo/Desktop/Python Project/automatic.py",line 11,in <module>
    while True (Now != lesson1 and Now != lesson2 and Now != lesson3):
TypeError: 'bool' object is not callable
[Finished in 0.053s]

谁能帮我解决这个问题?

解决方法

我认为你想要的条件是

while now != lesson1 and now != lesson2 and now != lesson3:

True (now != lesson1 and now != lesson2 and now != lesson3) 被认为是对 True 的函数调用,它不是可调用的,而是一个布尔值。

此外,我认为您可能希望在 if 循环之后移动三个 while,以便仅在 while 终止时检查三个可能值之间的时间。