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

Lloyd Hugh Allen chandrakirti at gmail.com
Fri Oct 22 12:16:43 CEST 2004


There's also a fairly common convention,

done = False
while not done:
    {do stuff}

then if you want to set an exit condition (perhaps the user selects
"quit" from a menu), the loop will stop repeating if you ever set done
= True.


On Fri, 22 Oct 2004 05:35:59 -0400, Kent Johnson
<kent_johnson at skillsoft.com> wrote:
> 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
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list