How to streamingly read text file and display whenever updated text

Nobody nobody at nowhere.com
Sat Oct 5 06:25:15 EDT 2013


On Sat, 05 Oct 2013 00:38:51 -0700, galeomaga wrote:

> #!/usr/bin/python
> import time
> f = open('/home/martin/Downloads/a.txt')
> while 1:
> 	for line in f:
> 		print line;
> 	time.sleep(1);

So you're trying to implement "tail -f"?

First, check that "tail -f" actually works for your particular use case.

If the process writing the file uses buffered output, data will only
actually be appended to the file when the buffer is full. You can't read
what isn't there.

And if the process creates a new file with the same name, rather than
appending to the existing file, you'll still be reading the old file. You
would need to open the file again to read the new file.




More information about the Python-list mailing list