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
On Wed, Jan 7, 2009 at 4:17 PM, Jim mickeyboa@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
On Wed, Jan 7, 2009 at 4:17 PM, Jim mickeyboa@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
I assume you're using this: http://petro.tanrei.ca/2007/02/my-alarm-clock/
You did not copy the whitespace appropriately. Python uses whitespace to delimit blocks.
-- fedora-list mailing list fedora-list@redhat.com To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines
Arthur Pemberton wrote:
On Wed, Jan 7, 2009 at 4:17 PM, Jim mickeyboa@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
I assume you're using this: http://petro.tanrei.ca/2007/02/my-alarm-clock/
You did not copy the whitespace appropriately. Python uses whitespace to delimit blocks.
-- fedora-list mailing list fedora-list@redhat.com To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines
White space WHERE ?? I no nothing about Python
On Wed, 2009-01-07 at 17:17 -0500, 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()) <- clauses in the body of a while must
be indented.
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
-- ======================================================================= Batteries not included. ======================================================================= Aaron Konstam telephone: (210) 656-0355 e-mail: akonstam@sbcglobal.net
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
Thanks Jim
In Python indentation matters. And it needs to be consistent within a block. The python interpreter is telling you that you should have started an indented block at the while but there is no indented block. Do a search for a python tutorial on the web or go to http://www.python.org and I think there is a link to a tutorial.
Do you have the original of the script? It should have the correct indentation. I've also indented it correctly above.
stan wrote:
In Python indentation matters. And it needs to be consistent within a block. The python interpreter is telling you that you should have started an indented block at the while but there is no indented block.
Incidentally, doesn't this also mean it's impossible to do the equivalent of:
while(true) { }
?
Matt Flaschen
On Wed, Jan 7, 2009 at 5:22 PM, Matthew Flaschen matthew.flaschen@gatech.edu wrote:
stan wrote:
In Python indentation matters. And it needs to be consistent within a block. The python interpreter is telling you that you should have started an indented block at the while but there is no indented block.
Incidentally, doesn't this also mean it's impossible to do the equivalent of:
while(true) { }
?
while True: pass
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
Matthew Flaschen wrote:
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
I ran yo $ python times.py Welcome to the talking alarm clock This program is public domain
Traceback (most recent call last): File "times.py", line 1, in <module> import time File "/home/mickey/time.py", line 8, in <module> t = time.localtime(time.time())
AttributeError: 'module' object has no attribute 'localtime'
Python is having problems of execute this line.
t = time.localtime(time.time())
On Wed, Jan 7, 2009 at 5:06 PM, Jim mickeyboa@sbcglobal.net wrote:
Matthew Flaschen wrote:
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
I ran yo $ python times.py Welcome to the talking alarm clock This program is public domain
Traceback (most recent call last): File "times.py", line 1, in <module> import time File "/home/mickey/time.py", line 8, in <module> t = time.localtime(time.time())
AttributeError: 'module' object has no attribute 'localtime'
Python is having problems of execute this line.
t = time.localtime(time.time())
1) This is getting offtopic 2) You need to at least send us the script you're using 3) There is no way that that line of code doesn't work if you did `import time` first 4) You may want to check and IRC channel such as irc://freenode.net/fedora
On Wed, Jan 7, 2009 at 5:18 PM, Arthur Pemberton pemboa@gmail.com wrote:
On Wed, Jan 7, 2009 at 5:06 PM, Jim mickeyboa@sbcglobal.net wrote:
Matthew Flaschen wrote:
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
I ran yo $ python times.py Welcome to the talking alarm clock This program is public domain
Traceback (most recent call last): File "times.py", line 1, in <module> import time File "/home/mickey/time.py", line 8, in <module> t = time.localtime(time.time())
AttributeError: 'module' object has no attribute 'localtime'
Python is having problems of execute this line.
t = time.localtime(time.time())
- This is getting offtopic
- You need to at least send us the script you're using
- There is no way that that line of code doesn't work if you did
`import time` first 4) You may want to check and IRC channel such as irc://freenode.net/fedora
Also, there are several alarm apps already in Fedora, it doesn't seem like you're trying to learn Python, so might be best to just use an already existing app.
Arthur Pemberton wrote:
On Wed, Jan 7, 2009 at 5:18 PM, Arthur Pemberton pemboa@gmail.com wrote:
On Wed, Jan 7, 2009 at 5:06 PM, Jim mickeyboa@sbcglobal.net wrote:
Matthew Flaschen wrote:
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
I ran yo $ python times.py Welcome to the talking alarm clock This program is public domain
Traceback (most recent call last): File "times.py", line 1, in <module> import time File "/home/mickey/time.py", line 8, in <module> t = time.localtime(time.time())
AttributeError: 'module' object has no attribute 'localtime'
Python is having problems of execute this line.
t = time.localtime(time.time())
- This is getting offtopic
- You need to at least send us the script you're using
- There is no way that that line of code doesn't work if you did
`import time` first 4) You may want to check and IRC channel such as irc://freenode.net/fedora
Also, there are several alarm apps already in Fedora, it doesn't seem like you're trying to learn Python, so might be best to just use an already existing app.
I told you in the beginning I know nothing about Python. I'm getting answers that assume, I know what your talking about, I don't, I just have a script that I'm asking how it works. What are the other scripts that are already in Fedora.
On Wed, Jan 7, 2009 at 5:57 PM, Jim mickeyboa@sbcglobal.net wrote:
Arthur Pemberton wrote:
I told you in the beginning I know nothing about Python. I'm getting answers that assume, I know what your talking about, I don't, I just have a script that I'm asking how it works. What are the other scripts that are already in Fedora.
Well, one doesn't need to know about Python to know what whitespace is.
That aside, look around your desktop programs there is probably an alarm program somewhere.
I know KDE at least used to have Kalarm
Arthur Pemberton wrote:
On Wed, Jan 7, 2009 at 5:57 PM, Jim mickeyboa@sbcglobal.net wrote:
Arthur Pemberton wrote:
I told you in the beginning I know nothing about Python. I'm getting answers that assume, I know what your talking about, I don't, I just have a script that I'm asking how it works. What are the other scripts that are already in Fedora.
Well, one doesn't need to know about Python to know what whitespace is.
That aside, look around your desktop programs there is probably an alarm program somewhere.
I know KDE at least used to have Kalarm
Thank you Authur
Jim wrote:
Arthur Pemberton wrote:
On Wed, Jan 7, 2009 at 5:18 PM, Arthur Pemberton pemboa@gmail.com wrote:
On Wed, Jan 7, 2009 at 5:06 PM, Jim mickeyboa@sbcglobal.net wrote:
Matthew Flaschen wrote:
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
I ran yo $ python times.py Welcome to the talking alarm clock This program is public domain
Traceback (most recent call last): File "times.py", line 1, in <module> import time File "/home/mickey/time.py", line 8, in <module> t = time.localtime(time.time())
AttributeError: 'module' object has no attribute 'localtime'
Python is having problems of execute this line.
t = time.localtime(time.time())
- This is getting offtopic
- You need to at least send us the script you're using
- There is no way that that line of code doesn't work if you did
`import time` first 4) You may want to check and IRC channel such as irc://freenode.net/fedora
Also, there are several alarm apps already in Fedora, it doesn't seem like you're trying to learn Python, so might be best to just use an already existing app.
I told you in the beginning I know nothing about Python. I'm getting answers that assume, I know what your talking about, I don't, I just have a script that I'm asking how it works. What are the other scripts that are already in Fedora.
I know nothing about python either..... But the comments of others has got me to ....
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
I added a "tab" to Lines 7 and 8 as well as a closing ) on Line 7. Note that blank lines are counted. Line 11 also has a tab added. Hope that helps...and I hope my formatting survives.
Ed Greshko wrote:
Jim wrote:
Arthur Pemberton wrote:
On Wed, Jan 7, 2009 at 5:18 PM, Arthur Pemberton pemboa@gmail.com wrote:
On Wed, Jan 7, 2009 at 5:06 PM, Jim mickeyboa@sbcglobal.net wrote:
Matthew Flaschen wrote:
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
I ran yo $ python times.py Welcome to the talking alarm clock This program is public domain
Traceback (most recent call last): File "times.py", line 1, in <module> import time File "/home/mickey/time.py", line 8, in <module> t = time.localtime(time.time())
AttributeError: 'module' object has no attribute 'localtime'
Python is having problems of execute this line.
t = time.localtime(time.time())
- This is getting offtopic
- You need to at least send us the script you're using
- There is no way that that line of code doesn't work if you did
`import time` first 4) You may want to check and IRC channel such as irc://freenode.net/fedora
Also, there are several alarm apps already in Fedora, it doesn't seem like you're trying to learn Python, so might be best to just use an already existing app.
I told you in the beginning I know nothing about Python. I'm getting answers that assume, I know what your talking about, I don't, I just have a script that I'm asking how it works. What are the other scripts that are already in Fedora.
I know nothing about python either..... But the comments of others has got me to ....
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
I added a "tab" to Lines 7 and 8 as well as a closing ) on Line 7. Note that blank lines are counted. Line 11 also has a tab added. Hope that helps...and I hope my formatting survives.
Thank you Ed.
On Wed, Jan 7, 2009 at 10:52 PM, Jim mickeyboa@sbcglobal.net wrote:
Ed Greshko wrote:
Jim wrote:
Arthur Pemberton wrote:
On Wed, Jan 7, 2009 at 5:18 PM, Arthur Pemberton pemboa@gmail.com wrote:
On Wed, Jan 7, 2009 at 5:06 PM, Jim mickeyboa@sbcglobal.net wrote:
Matthew Flaschen wrote:
> 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 > > > I ran yo $ python times.py Welcome to the talking alarm clock This program is public domain
Traceback (most recent call last): File "times.py", line 1, in <module> import time File "/home/mickey/time.py", line 8, in <module> t = time.localtime(time.time())
AttributeError: 'module' object has no attribute 'localtime'
Python is having problems of execute this line.
t = time.localtime(time.time())
- This is getting offtopic
- You need to at least send us the script you're using
- There is no way that that line of code doesn't work if you did
`import time` first 4) You may want to check and IRC channel such as irc://freenode.net/fedora
Also, there are several alarm apps already in Fedora, it doesn't seem like you're trying to learn Python, so might be best to just use an already existing app.
I told you in the beginning I know nothing about Python. I'm getting answers that assume, I know what your talking about, I don't, I just have a script that I'm asking how it works. What are the other scripts that are already in Fedora.
I know nothing about python either..... But the comments of others has got me to ....
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
I added a "tab" to Lines 7 and 8 as well as a closing ) on Line 7. Note that blank lines are counted. Line 11 also has a tab added. Hope that helps...and I hope my formatting survives.
#!/usr/bin/env python
import time import os
not_executed = 1
while (not_executed): dt = list(time.localtime(time.time())) hour = dt[3] minute = dt[4] if hour == 22 and minute == 58: os.spawnv (os.P_WAIT, "/usr/bin/mpg123", ["mpg123", "/home/mp3/Abba/Gold/queen.mp3"] ) not_executed = 0
On Wed, Jan 7, 2009 at 11:01 PM, Paulo Cavalcanti promac@gmail.com wrote:
On Wed, Jan 7, 2009 at 10:52 PM, Jim mickeyboa@sbcglobal.net wrote:
Ed Greshko wrote:
Jim wrote:
Arthur Pemberton wrote:
On Wed, Jan 7, 2009 at 5:18 PM, Arthur Pemberton pemboa@gmail.com wrote:
On Wed, Jan 7, 2009 at 5:06 PM, Jim mickeyboa@sbcglobal.net wrote:
> Matthew Flaschen wrote: > > >> 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 >> >> >> > I ran yo > $ python times.py > Welcome to the talking alarm clock > This program is public domain > > Traceback (most recent call last): > File "times.py", line 1, in <module> > import time > File "/home/mickey/time.py", line 8, in <module> > t = time.localtime(time.time()) > > AttributeError: 'module' object has no attribute 'localtime' > > Python is having problems of execute this line. > > t = time.localtime(time.time()) > >
- This is getting offtopic
- You need to at least send us the script you're using
- There is no way that that line of code doesn't work if you did
`import time` first 4) You may want to check and IRC channel such as irc://freenode.net/fedora
Also, there are several alarm apps already in Fedora, it doesn't seem like you're trying to learn Python, so might be best to just use an already existing app.
I told you in the beginning I know nothing about Python. I'm getting answers that assume, I know what your talking about, I don't, I just have a script that I'm asking how it works. What are the other scripts that are already in Fedora.
I know nothing about python either..... But the comments of others has got me to ....
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
I added a "tab" to Lines 7 and 8 as well as a closing ) on Line 7. Note that blank lines are counted. Line 11 also has a tab added. Hope that helps...and I hope my formatting survives.
#!/usr/bin/env python
import time import os
not_executed = 1
while (not_executed): dt = list(time.localtime(time.time())) hour = dt[3] minute = dt[4] if hour == 22 and minute == 58: os.spawnv (os.P_WAIT, "/usr/bin/mpg123", ["mpg123", "/home/mp3/Abba/Gold/queen.mp3"] ) not_executed = 0
If you want something more generic, to be called passing parameters, such as, "alarm.py 23 15"
#!/usr/bin/env python
import time import os import sys
def alarm (h, m): while (True): dt = list(time.localtime(time.time())) hour = dt[3] minute = dt[4] if hour == h and minute == m: os.spawnv (os.P_WAIT, "/usr/bin/mpg123", ["mpg123", "/home/mp3/Abba/Gold/queen.mp3"] ) break
def main(argv=None): if argv is None: argv = sys.argv
if len(argv) < 3: print "Two arguments are needed." return 1 else: if not (argv[1].isdigit() and argv[2].isdigit()): print "An hour and minute are expected." return 1
alarm(int(argv[1]),int(argv[2]))
return 0
if __name__=="__main__": sys.exit(main())
Arthur Pemberton wrote:
On Wed, Jan 7, 2009 at 5:06 PM, Jim mickeyboa@sbcglobal.net wrote:
Matthew Flaschen wrote:
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
I ran yo $ python times.py Welcome to the talking alarm clock This program is public domain
Traceback (most recent call last): File "times.py", line 1, in <module> import time File "/home/mickey/time.py", line 8, in <module> t = time.localtime(time.time())
AttributeError: 'module' object has no attribute 'localtime'
Python is having problems of execute this line.
t = time.localtime(time.time())
- This is getting offtopic
- You need to at least send us the script you're using
- There is no way that that line of code doesn't work if you did
`import time` first 4) You may want to check and IRC channel such as irc://freenode.net/fedora
The script you see at the top of this email is the script I downloaded.