[Tutor] File Access
isrgish at fastem.com
Fri Apr 9 01:20:11 EDT 2004
Nick Lunt wrote:
>thanks for the info. However, f.seek(0,2) takes me to the end of the
>file as you say, but what I need is the whole last line of the file.
>After doing f.seek(0,2) successive f.seek(-1, 1) calls will walk me
>backwards through the file but to make this useful I would need to keep
>checking the current character for an "\n". And unfortunately calls to
>f.read() and f.readline() take me back to the end of the file or line
You can try reading a chunk that you are sure is more than the length of the longest line. Then do str.rfind('\n') to find the last line.
All the best
>Im on linux and the fseek(3) manpage seems to indicate that I cannot
>take a file of unknown size and seek to the start of the last line,
>would be nice if it did tho ;)
>Am I talking rubbish or do you agree ?
More information about the Tutor