想让程序每月执行一次,使用 Python 的 schedule 模块,请给出示例,不要用schedule.every().month
时间: 2023-02-02 20:41:54 浏览: 83
使用 Python 的 schedule 模块,每月执行一次的示例代码如下:
```
import schedule
import time
def job():
print("Job is running!")
schedule.every().day.at("12:00").do(job)
while True:
schedule.run_pending()
time.sleep(1)
```
代码中的 `schedule.every().day.at("12:00").do(job)` 表示每天的12点钟执行 `job` 函数。如果改成每月的1号的12点钟执行,可以这样写:
```
import schedule
import time
def job():
print("Job is running!")
schedule.every().month.at("12:00").do(job)
while True:
schedule.run_pending()
time.sleep(1)
```