Yet another one of David Beazley code samples from his Generator Tricks For Systems Programmers. This one acts like a tail -f, reading any new lines added to a file. More information on this can be found at http://www.dabeaz.com/.
Here is the source code, pretty small but extremely useful when working with log files.
import time def monitor(file): file.seek(0,2) while True: line = file.readline() if not line: time.sleep(0.1) continue yield line