how to read the last line of a huge file???

tkpmep at hotmail.com tkpmep at hotmail.com
Fri Mar 4 16:46:32 EST 2011


I've implementing this method of reading a file from the end, i.e

def seeker(filename):
    offset = -10
    with open(filename) as f:
        while True:
            f.seek(offset, os.SEEK_END)
            lines = f.readlines()
            if len(lines) >= 2:
                return lines[-1]
            offset *= 2

and consistently run into the following error message when Python 3.2
(running under Pyscripter 2.4.1) tries to execute the line
f.seek(offset,2)

UnsupportedOperation: can't do non-zero end-relative seeks

But offset is initialized to -10. Does anyone have any thoughts on
what the error might be caused by?

Thanks in advance

Thomas Philips





More information about the Python-list mailing list