Python Guru needed

Matthew Flaschen matthew.flaschen at gatech.edu
Wed Jan 7 22:48:24 UTC 2009


Jim 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

It's because of Python's always charming significant whitespace.  I.E.
Python uses indenting instead of braces, making problems like this
extremely common.  (No sane language even has "IndentationErrors". Also,
you were missing a paren, but that's not what caused the error above.

A correct version is attached.  Hopefully it will not get mangled by
your client.

Matt Flaschen
-------------- next part --------------
A non-text attachment was scrubbed...
Name: python_alarm.py
Type: text/x-python
Size: 248 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/fedora-list/attachments/20090107/edc4bf63/attachment-0001.py>


More information about the fedora-list mailing list