0

I want to make a program that checks the current time of the pc,

from datetime import datetime
now = datetime.now()

hour = str(now.hour)
min = str(now.minute)

This code gets the current time. But i would like to add additonal options, such that if the hour = 12 and min = 15 run a code

If the hour = 11, the program would wait till the hour reaches 12 and then run the code

olly_uk
  • 10,711
  • 3
  • 38
  • 45
  • 1
    is it really necessary for the python code to check (i.e. will it be a continuously running daemon) or could a scheduling tool like cron be good enough? – olly_uk Oct 07 '13 at 16:09
  • Yep use cron or if on windows read http://stackoverflow.com/questions/132971/what-is-the-windows-version-of-cron – YXD Oct 07 '13 at 16:09
  • oops, just noticed the date on the question, not sure how it ended up the top of the main page? – olly_uk Oct 07 '13 at 16:10
  • 1
    @olly_uk The main page sorts by activity. Anyway, dealing with old questions is positively encouraged. – Marcin Oct 07 '13 at 16:31

1 Answers1

2

In general, don't do this yourself. All operating systems have tools to automate periodic running of tasks, such as cron on *nix systems, and windows task scheduler on windows.

Marcin
  • 44,601
  • 17
  • 110
  • 191