[Tutor] How to watch a changing list, and wait for a certain value to leave?

Eric eric at digitalert.net
Fri Oct 15 09:20:26 CEST 2004

I got some help here before with this program I have started to write, 
and I am hung up on something again. Anyway I'm trying to write a simple 
program that will watch for a connection to be made by a certain host, 
sound the system bell when the connection is made, and then when the 
connection is closed have the system bell sound again. Then loop back to 
the beginning and start watching again. Here is the only working part I 
have so far...

import os
import time

connected = False

while not connected:
    o=os.popen("netstat -an")
    for l in o:
            if l.split()[1].endswith(""):
                print "\a\a\a\a\aMatch!"
                connected = True
                print "Nothing"   
        except IndexError:
            print "Index Exception"

That works just like I want it to however now I need to figure out a way 
to know when the host disconnects. I have tried to use count() function 
in conjunction with the less than operator to wait till 
"" is <1 , but can't seem to get it right. Can anyone 
give me a hint, but not write the entire thing for me, or maybe give me 
some insite on a better way to do this?


More information about the Tutor mailing list