【发布时间】:2021-06-07 09:23:36
【问题描述】:
所以,我正在尝试使用 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]
谁能帮我解决这个问题?
【问题讨论】:
-
True (now != lesson1 and now != lesson2 and now != lesson3)被认为是调用带有括号中的参数的方法True所以这就是你得到错误的原因。你想添加什么作为条件? -
你有
while True (...)。我想你想删除True。
标签: python loops while-loop boolean boolean-operations