Understanding "tail -f in python"

I created a very simple python script:

def read_then_follow(file):
    for line in file:
        yield line
    while True:
        line = file.readline()
        if not line:
            time.sleep(1.0)
            continue
        yield line

for line in read_then_follow("some_file.txt"): print line

The file "some_file.txt" contains several lines of text that will be written to the screen when the script starts. If I then add a line to the file with echo "line" >> some_file.txt, the line will be printed on the screen for 1 second. But: if I open the file in vim, add the line below and save, the script will stop functioning. It does not write a new line written in vim to the screen and does not respond to additional commands echo ....

For your information, I am currently using python 2.6.6 on Ubuntu 10.10.

+3
source share
1 answer

(I assume that you are running on some kind of operating system like Unix.)

vim . , script, - , . script , 0 .

+8

All Articles