mysteriously nonfunctioning script - very simple

S

Sean McIlroy

Can anybody help me make sense of the fact that the following script
doesn't work? It's so simple I can't imagine what I'm missing. Any
help will be much appreciated.

Peace,
STM


## ALARM CLOCK:
from time import sleep,time,localtime

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'
 
P

Piet van Oostrum

SM> Can anybody help me make sense of the fact that the following script
SM> doesn't work? It's so simple I can't imagine what I'm missing. Any
SM> help will be much appreciated.

What do you mean `it doesn't work'?
 
P

Peter Hansen

Sean said:
Can anybody help me make sense of the fact that the following script
doesn't work? It's so simple I can't imagine what I'm missing. Any
help will be much appreciated.

Always post actual tracebacks of the problem, if
indeed it is producing a traceback. Do this always
by *cut and paste*, not by retyping the text. Make
sure not to remove anything important, and make sure
you are running the actual code you have posted here.

Also always describe the problem in more detail than
just "doesn't work". For all we know, the code runs
fine but its output just doesn't suit you...

-Peter
 
D

Dennis Lee Bieber

Can anybody help me make sense of the fact that the following script
doesn't work? It's so simple I can't imagine what I'm missing. Any
help will be much appreciated.

Peace,
STM


## ALARM CLOCK:
from time import sleep,time,localtime

wakeuptime = input('hours: '), input('minutes: ')

Use of input() is not recommended... Use raw_input() and
explicitly convert the data.
onehourlater = (wakeuptime[0]+1, wakeuptime[1])
while not wakeuptime < localtime(time())[3:5] < onehourlater:

How about putting some parentheses on that... I tend to read it
as (not wakeuptime) < ...


--
 
S

Sean McIlroy

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
######################################################################
 
D

Diez B. Roggisch

######################################################################
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:
False

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

Peter Otten

Sean said:
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)

Maybe you are a little /impatient/ and want to change the above to

while not wakeuptime <= localtime(time())[3:5] < onehourlater: sleep(3)

That should wake you up roughly one minute earlier, and thus before you hit
Ctrl+C ...again.

Peter
 
M

Michael Spencer

Sean said:
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]
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
 
H

Heiko Wundram

Am Samstag, 26. März 2005 19:47 schrieb Sean McIlroy:

Why not try the following:

--
--- Heiko.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQBCRcumf0bpgh6uVAMRAldgAJ97TtSMB3UtpMzJBXkNIWB1s6uxGwCdGR6u
zwX3yJ4CP/sKWmVJBM23LnQ=
=Lfc2
-----END PGP SIGNATURE-----
 
S

Sean McIlroy

Why not try the following:
<snip>

I did try it, and it didn't work either. It appears there must be
something wrong with my computer, hopefully something benign. Thanks
anyway.

Peace,
STM
 
G

Greg Ewing

Sean said:
I did try it, and it didn't work either. It appears there must be
something wrong with my computer, hopefully something benign.

Just a thought: Is your computer's clock set correctly?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top