79263222

Date: 2024-12-08 19:48:04
Score: 1
Natty:
Report link

Using seek(), read() and readline(),
I can rapidly retrieve the last line of a text file :

with open("My_File", "r") as f:
     n = f.seek(0,2)
     for i in range(n-2, 1, -1):
             f.seek(i)
             if f.read(1)=="\n":
                     s = f.readline()[:-1]
                     break
Reasons:
  • Low length (0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Tawal