On Wed, Jan 7, 2009 at 4:17 PM, Jim <mickeyboa(a)sbcglobal.net> wrote:
FC 10/KDE
I'm trying to set a simple Alarm Clock in FC10 and I have a Python script I
picked up, but I have error, running the script.
Can you explain to me with # comments on each line how to make this work.
import time
import os
not_executed = 1
while(not_executed):
dt = list(time.localtime(time.time())
hour = dt[3]
minute = dt[4]
if hour == 5 and minute == 45:
os.popen2("open /Users/jun/shout.mp3")
not_executed = 0
Error Message;
$ python AlarmClock
File "AlarmClock", line 7
dt = list(time.localtime(time.time())
^
IndentationError: expected an indented block
Thanks Jim
Whitespace is important in Python, some hate it some love it for that.
Anything that is part of the while statement (after the while
statement itself) needs to be indented, it doesn't matter how much as
long as it's the same amount for each line within the while statement.
The next line after your while statement should be unindented.
import time
import os
not_executed = 1
while(not_executed):
dt = list(time.localtime(time.time())
hour = dt[3]
minute = dt[4]
if hour == 5 and minute == 45:
os.popen2("open /Users/jun/shout.mp3")
not_executed = 0
So if I interpreted what you were trying to do correctly it should
look something like the above. Although I'm not sure you can call the
if statement like that. maybe try "if dt == [5,45]: or something like
that, my python is a bit rusty.
Richard