python program to watch a file - example.

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

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

> 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

tail -f is roughly equivalent to:

    while 1:

        line = fp.readline()

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


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

More information about the Python-list mailing list