Hi guys, been googling for about 20 minutes without no luck. All I find is how to print out the last line or how to find the last line… but not how to print the 10 last lines.
This is the code:
f = open('textfil.txt', 'r')
for line in f:
print(line)
f.close()
This prints out the lines in the text file but how do I do to just print out the 10 last lines? Using loop if possible,
Example if the lines are:
1
2
3
4
5
6
7
8
9
10
11
Then the print should be:
2
3
4
5
6
7
8
9
10
11
Would also like to know how to print the 10 last lines in reverse if you guys know how to like this:
11
10
9
8
and so on…
Thanks in advance for the help!