【发布时间】:2022-08-16 16:43:08
【问题描述】:
我正在使用计划模块提醒我每十秒喝一次水
import schedule
def remindDrink():
print(\"Drink Water\")
while True:
schedule.every().day.at(\"16:35\").do(remindDrink())
所以这里的问题是任务被执行,但不是在给定时间立即执行,并且 VSCode 向我抛出了一个奇怪的错误
Traceback (most recent call last):
File \"e:\\Code\\Python Code\\randomModule.py\", line 12, in <module>
schedule.every().day.at(\"16:31\").do(sendNotification())
File \"C:\\Users\\PC\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\schedule\\__init__.py\", line 625, in do
self.job_func = functools.partial(job_func, *args, **kwargs)
TypeError: the first argument must be callable
PS E:\\Code\\Python Code>
这是错误,我做错了什么?
-
为什么将它安排在一个while循环中?您只需执行一次,它将按照选定的时间表运行。
-
您应该将 schedule.run_pending() 放在 while 循环中。参考schedule.readthedocs.io/en/stable/…
-
这是这个问题所显示的stackoverflow.com/questions/67575348/…
-
哦等等,我正在查看错误中的代码,而不是解决方案