mysteriously nonfunctioning script - very simple

Diez B. Roggisch deetsNOSPAM at web.de
Sat Mar 26 14:01:41 EST 2005


> ######################################################################
> from time import sleep,time,localtime
> 
> wakeuptime = (7,00)
> ## I WANT TO BE WOKEN UP AT 7AM (FOR EXAMPLE)
> 
> onehourlater = (wakeuptime[0]+1, wakeuptime[1])
> ## ONE HOUR LATER THAN THAT IS 8AM
> 
> while not wakeuptime < localtime(time())[3:5] < onehourlater: sleep(3)
> ## CHECK THE CURRENT TIME EVERY 3 SECONDS, AND IF IT'S NOT BETWEEN
> ## 7AM AND 8AM, GO BACK TO SLEEP FOR ANOTHER 3 SECONDS
> 

It does work for me:

>>> wakeuptime = (19,00)
>>> onehourlater = (20,00)
>>> lt = (18,59)
>>> not wakeuptime < lt < onehourlater
True

>>> lt = (19:01)
>>> not wakeuptime < lt < onehourlater
False

And localtime(time())[3:5] returns the desired timetuple. You're sure that's
not working?

-- 
Regards,

Diez B. Roggisch



More information about the Python-list mailing list