def watch(fn, words):
    fp = open(fn, 'r')
while True:
    new = fp.readline()
if new:
    for word in words:
        if word in new:
            yield word, new
else:
    time.sleep(0.5)
fn = 'test.py'
words = ['word']
for hit_word, hit_sentence in watch(fn, words):
    pass
How to implement a pythonic equivalent of tail -F?