python program to watch a file - example.

Chris Gonnerman chris.gonnerman at newcenturycomputers.net
Sun Sep 8 10:30:48 EDT 2002


----- Original Message ----- 
From: "Tim Hoffman" <timh at zute.net>

> If it is always the same file and seeing you are looking at *nix 
> varient, one of the unix like ways would be to tail -f the file, and 
> hook it up to your process which just does blocking reads on stdin.
> 
> ie tail -f somfile | python my_watch.py

tail -f is roughly equivalent to:

    while 1:

        line = fp.readline()

        while line:
            print line
            line = fp.readline()

        time.sleep(1)

You would use a break to get out of this; or you might want
some other sort of exit condition.


Chris Gonnerman -- chris.gonnerman at newcenturycomputers.net
http://newcenturycomputers.net





More information about the Python-list mailing list