为什么 'bool' 对象不可调用?

Why 'bool' object is not callable?

因此,我正在尝试使用 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 的函数调用,它不是可调用的,而是一个布尔值。

此外,我想你可能想在 while 循环之后移动三个 ifs,这样只有在 while 终止时才会检查三个可能的时间值。