What would be the best way to go about reading the last 20 lines from a txt file?
The only thing I can think of is, check how many lines there are, and make it read the last 20 ones. Which involves a calculation for each line read...problem is - I'm not able to put it into code. Does anybody know a way to do this...or even a better way to read last 20 lines?
genius3k wrote:What would be the best way to go about reading the last 20 lines from a txt file?
The only thing I can think of is, check how many lines there are, and make it read the last 20 ones. Which involves a calculation for each line read...problem is - I'm not able to put it into code. Does anybody know a way to do this...or even a better way to read last 20 lines?
Thanks, later.
If your file is not too big, you can use a simple procedure.
- [read] in the complete file at once
- [split] the file into a list around the newline character
- take the last 20 elements of that list