问题
In my python program, I would like it to run a piece of code at a pre-defined time every weekday, let say 2pm Mon - Fri.
How may I do it please?
回答1:
You can use "schedule" library
to install, on terminal enter:
pip install schedule
here is an example of the code you want:
#!/usr/bin/python
import schedule
import time
def job():
print("I am doing this job!")
schedule.every().monday.at("14:00").do(job)
schedule.every().tuesday.at("14:00").do(job)
schedule.every().wednesday.at("14:00").do(job)
schedule.every().thursday.at("14:00").do(job)
schedule.every().friday.at("14:00").do(job)
while True:
schedule.run_pending()
time.sleep(1)
or you can read the documents to see the other functions Click Here
good luck!
来源:https://stackoverflow.com/questions/43670224/python-to-run-a-piece-of-code-at-a-defined-time-every-day