0

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?

1
  • You never change now... Your loop change runs and runs with the same value so all conditions will be the same. You need to change the value of now inside the loop Commented Dec 9, 2020 at 14:37

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

well silly me, i didn't notice that the now was outsid, thanks for helping and thanks for the advice with sleep, it's certainly better

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.