[Tutor] File Access
Nick Lunt
nick at javacat.f2s.com
Sun Apr 4 13:26:53 EDT 2004
Hi folks,
I need to go to the last line of a file and then to the start of a
delimited section of that line, such as
$ cat file.txt
var1|var2|var3|var4|var5|var6|var7
var1|var2|var3|var4|var5|var6
var1|var2|var3|var4|var5|var6
What I want to do is goto the last line in the imaginary file.txt above
and extract var3 for example.
I could probably do a realines() until EOF overwriting a variable with
the contents of each line so that at the end the variable will hold the
contents of just the last line, or by putting each line of the file into
a list and pulling the last element of the list out, but eventually the
file.txt will get pretty big, so I thought of using seek().
However, I could not find on python.org or by googling any way to do
this.
So can anyone please give me a hint on the most efficient way to grab
the contents of the last line of a large text file please ?
Kind regards,
Nick.
More information about the Tutor
mailing list