To read text file line by line in reverse
for line in reversed(open('main.py').readlines()): print(line.rstrip())