1

how can I loop print something 5 times every minute like when 09.01 am print something 5 times then do nothing till 09.02 am and print other things 5 times then do nothing

4

1 Answer 1

1

Here are some elements of answer:

  • datetime.datetime.now() gives you the time of, well, now. Use it to check whether it's 10 am
  • time.sleep allows you to pause your program for a given number of second (say 60 to make 1 minute)
  • while True allows you to run a program continuously

Also, note that it is probably not the best approach. On linux and mac you have utilities such as cron to do that. Pretty sure something exists on Windows as well. Bottom line: scheduling is best managed by your os, not by a python script.

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

3 Comments

guess you might also want to point to something async; typically you don't want the timer of your scheduled task block all the rest of your code
@MrFuppes true that
Thanks, everyone, that exactly what I wanted to do.

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.