I get the last 10 lines from the TXT file like this:
a_file = open("log.txt", "r")
lines = a_file.readlines()
last_lines = lines[-10:]
Get the answer like this:
c
d
e
f
g
How do sort the result so that last line is on top?
g
f
e
d
c
I get the last 10 lines from the TXT file like this:
a_file = open("log.txt", "r")
lines = a_file.readlines()
last_lines = lines[-10:]
Get the answer like this:
c
d
e
f
g
How do sort the result so that last line is on top?
g
f
e
d
c
Use reversed() to read a file line by line backwards:
a_file = open("log.txt", "r")
lines = a_file.readlines()
for line in reversed(lines):
print(line)