我有一个代码,我希望代码在两个不同的时间运行。例如,当我运行代码时,我希望它运行第一行:
print("Hello world")
然后我希望它在某个时间运行剩余的代码(即美国东部时间11:23:31):
print("Hello again")
我可以用什么模块在Python中执行此操作?
实际代码比仅仅" Hello world"复杂得多。 我是编码的新手。
答案 0 :(得分:3)
您可以使用schedule library
import schedule
import time
import sys
def job1():
print("hello world")
def job2():
print("Hello again")
sys.exit(0) # remove this if you want it to run every day at 11:23
schedule.every().day.at("11:23").do(job2)
job1()
while True:
schedule.run_pending()
time.sleep(1)