[Tutor] Repeat function until...
Hello everyone, I'm new at programming with python and have a question about how I can solve my problem the correct way. Please forgive my grammar, English is not my primary language. I'm looking for a way to repeat my function every 30 seconds. As an example I have written a ping function. But I would like this function to repeat itself every 30 seconds, without stopping until I give it a STOP command (if such a thing exists.) Code: import os, sys def check(host): try: output = os.popen('ping -ns 1 %s' % host).read() alive = output.find('Reply from') print alive if alive is -1: print '%s \t\t DOWN ' % host else: print '%s \t\t OK' % host except OSError, e: print e sys.exit() check('www.google.com') Let me know if anything is unclear or if there are other recommendations about doing some parts different. Kind regards, Nethirlon ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Repeat function until...
On Wed, Jun 23, 2010 at 10:13 PM, Steven D'Aprano wrote: > On Thu, 24 Jun 2010 04:09:38 am Alan Gauld wrote: >> "Steven D'Aprano" wrote >> >> > The easiest way is to just run forever, and stop when the user >> > interrupts it with ctrl-D (or ctrl-Z on Windows): >> >> I think that would be Ctrl-C on both. >> Ctrl-D/Z is EOF not Interrupt. Certainly on Windows Ctrl-Z won't >> interrupt a loop. > > Doh! > > Thanks for the correction. > > > -- > Steven D'Aprano > ___ > Tutor maillist - tu...@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > Thank you all for replying to my question. It helped a lot and I have the solution to my problem thanks to you all! Kind regards, Nethirlon ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] os.startfile?
On Thu, Jun 24, 2010 at 7:36 PM, Jim Byrnes wrote: > I am trying to run an example program that contains the line > os.startfile('socket-nongui.py') which is Windows only. What would be the > command to use on Linux? All files are in the same folder. > > Thanks, Jim > ___ > Tutor maillist - tu...@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > Hi Jim, Is this perhaps what you are looking for? import os os.system('ls -lt > output.txt') Kind regards, Nethirlon ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor