So I need my program to run a task every given hour of a given day, I looked for a module that could easily do it and it exists, the schedule one, unfortunately we do not have it at my company's computer and I am not allowed to install anything, so I thought of something like this as a solution
import datetime
now = datetime.datetime.now()
while True:
if now.strftime("%d") == '09':
if now.strftime("%H") == '18':
do something
but it does not quite work as expected, if i Run the program at the schedulled time it runs normally, but if it's not, it does nothing when the time comes
what can I do?
You've defined now
outside the loop at the start of the program. Once running, it never changes. Set now
inside the loop, and consider using sleep
to let this program not waste resources as much.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.