Does anyone know why when you iterate over a file this way:
Entrance:
f = open('test.txt', 'r') for line in f: print "f.tell(): ",f.tell()
Output:
f.tell(): 8192 f.tell(): 8192 f.tell(): 8192 f.tell(): 8192
I constantly get the wrong file index from tell (), however, if I use readline, I get the corresponding index for tell ():
Entrance:
f = open('test.txt', 'r') while True: line = f.readline() if (line == ''): break print "f.tell(): ",f.tell()
Output:
f.tell(): 103 f.tell(): 107 f.tell(): 115 f.tell(): 124
I am running python 2.7.1 BTW.
source share