def follow(the_file):
    """
    Follow a given file and yield new lines when they are available, like `tail -f`.
    """
    with open(the_file) as f:
        f.seek(0, 2)  # seek to eof
        while True:
            line = f.readline()
            if not line:
                time.sleep(0.1)  # sleep briefly before trying again
                continue
            yield line
def follow ( the_file ) : with open ( the_file ) as f : f . seek ( 0 , 2 ) while True : line = f . readline ( ) if not line : time . sleep ( 0.1 ) continue yield line
Follow a given file and yield new lines when they are available, like `tail -f`.