I don’t get why the tell() function doesn’t work in this case. Let’s create a file with the string “1\n2\n3\n4\n” inside:
f=open('test.tmp','w')
f.write('1\n2\n3\n4\n')
f.close()
Now, let’s open it and run the following code:
fTellResults=[]
f=open('test.tmp','r+')
for line in f:
fTellResults.append(f.tell())
f.close()
print fTellResults
As a result I get:
[8L, 8L, 8L, 8L]
However, I would expect rather this:
[2L, 4L, 6L, 8L]
Could anyone explain me why it works like this and how could I get the expected result?
p.s. I use Python 2.7.1 on Linux
Based on this I claim the position given by
file.tellis incorrect because the file was already read to the read-ahead buffer.