I want to open a file and read each line using
f = open('test.txt', 'r')
last_pos = f.tell() # get to know the current position in the file
last_pos = last_pos + 1
f.seek(last_pos) # to change the current position in a file
ok, you may use this:
f = open( ... ) f.seek(last_pos) line = f.readline() # no 's' at the end of `readline()` last_pos = f.tell() f.close()
last_pos is not a line number in your file, it's a byte offset from the beginning of the file -- there's no point in incrementing/decrementing it.