mysteriously nonfunctioning script - very simple

Michael Spencer mahs at telcopartners.com
Sat Mar 26 20:41:58 CET 2005


Sean McIlroy wrote:
> Fair enough. Here's the verbose version:
> 
> ######################################################################
> 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
> 
> ## CONTROL NEVER REACHES THIS POINT
> ######################################################################
> 

Works for me in the following slightly-adjusted form (easier for testing):

def alarm(wakeuptime):
     #wakeuptime = input('hours: '), input('minutes: ')
     onehourlater = (wakeuptime[0]+1, wakeuptime[1])
     while not wakeuptime < localtime(time())[3:5] < onehourlater:
         sleep(3)
     print 'PLAY A SOUND FILE'
     print localtime(time())[3:5]

  >>> localtime(time())
  (2005, 3, 26, 11, 37, 58, 5, 85, 0)
  >>> alarm((11,38))
  PLAY A SOUND FILE
  (11, 39)
  >>>
  >>> import sys
  >>> sys.version
  '2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)]'
  >>> sys.platform
  'win32'
  >>>

Michael





More information about the Python-list mailing list