Issue
How to read a file in reverse order using python? I want to read a file from last line to first line.
Solution
for line in reversed(open("filename").readlines()):
print line.rstrip()
And in Python 3:
for line in reversed(list(open("filename"))):
print(line.rstrip())
Answered By - Matt Joiner
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.