[Tutor] A way to restart a script after it runs?

Kent Johnson kent_johnson at skillsoft.com
Fri Oct 22 11:35:59 CEST 2004


Congratulations! You've been working on this for a while!

This use of a while loop is fine. You don't have to invent a true 
condition, though; "while True:" works just fine.

Kent

At 04:00 AM 10/22/2004 -0400, Eric wrote:
>I ended up just putting in a while loop at the start of the script that 
>will always be "true", and then indented everything else below it. I kinda 
>figured that would be how I would have to do it, but either way it works 
>just fine.
>
>And without further adu here is my first completed Python project that I 
>didn't copy out of a book.. .
>
>
>import os
>import time
>
>z = 2
>
>while z ==2:
>
>    connected = False
>    while not connected:
>        o=os.popen("netstat -an")
>        for l in o:
>            try:
>                if l.split()[1].endswith("192.168.0.250:21"):
>                    print "\a\a\a\a\aMatch!"
>                    connected = True
>                else:
>                    print "Nothing"
>            except IndexError:
>                print "Index Exception"
>        time.sleep(1)
>
>    amount=0
>    while connected:
>        o=os.popen("netstat -an")
>        for l in o:
>            try:
>                if l.split()[1].endswith("192.168.0.250:21"):
>                    print "Still There"
>                    connected = True
>                    amount +=1
>                    print amount
>                else:
>                    print "Nothing"
>            except IndexError:
>                print "Index Exception"
>        time.sleep(1)
>        if amount == 1:
>            amount -=1
>        else:
>            print "It's Gone"
>            connected = False
>
>    print "\a\a"
>
>raw_input("Press Enter to close")
>
>
>
>
>
>Nothing fancy, but a good learning experience none the less.
>
>
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list