在python中,如何在暂停库中没有日期的情况下暂停到特定时间

问题描述

我有 python 脚本,我希望它在上午 10 点运行。我尝试使用暂停和日期时间库,如下面的代码

import pause
import datetime
pause.until(datetime.datetime(2021,1,6,10,00))

这意味着脚本将暂停到 2021 年 1 月 6 日上午 10 点。我想要的是,如何只暂停特定的时间,只有小时、分钟和秒,而不把日期放在那里?有可能吗?

解决方法

看看这个图书馆。我认为它会满足您的需求:https://pypi.org/project/schedule/

您可以编写以下代码:

import schedule
import time

def job():
    print("I'm working...")

schedule.every().day.at("10:30").do(job)

while True:
    schedule.run_pending()
    time.sleep(1)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...