SyntaxFix
Write A Post
Hire A Developer
Questions
If you can pick a reasonable maximum line length, you can seek to nearly the end of the file before you start reading.
myfile.seek(-max_line_length, os.SEEK_END) line = myfile.readlines()[-1]