(I'm an experienced programmer, but a python noob)
In the following test code, I open a text file, and seek to EOF.
Then, once/second, I try to read any new lines.
However, the file object sees no increase in file length even when 1000 new 100-char. lines are added(!)
(Same result in python v2.5.2 on Ubuntu 8.04 & v2.6.5 on Scientific Linux 5.4)
What perfectly obvious thing am I missing here?
Expand|Select|Wrap|Line Numbers
- #!/usr/bin/python2.6
- import os
- import stat
- import time
- filename = "testfile.txt"
- f = open (filename, "r")
- f.seek(0, 2)
- while True:
- line = f.readline()
- size1 = os.stat(filename)[stat.ST_SIZE]
- size2 = os.fstat(f.fileno())[stat.ST_SIZE]
- print "size1 =", size1, "; size2 =", size2, "; line = \"" + line + "\""
- time.sleep(1)
---- output ---- (1000 new lines pasted into file after 2nd line)
:
size1 = 10 ; size2 = 10 ; line = ""
size1 = 10 ; size2 = 10 ; line = ""
size1 = 100010 ; size2 = 10 ; line = ""
size1 = 100010 ; size2 = 10 ; line = ""
: