import collections,cStringIO def rev_readlines(arg): f=open(arg,'rb') f.seek(0,2)# go to the end line=collections.deque() while f.tell(): f.seek(-1,1) c=f.read(1) f.seek(-1,1) line.appendleft(c) if c =='\n': yield ''.join(line).strip() line.clear() #clear for next line yield ''.join(line).strip() #bit of optimization, load groups of bytes from disk into memory def rev_readlines2(arg,bufsize=8192): f1=open(arg,'rb') f1.seek(0,2)# go to the end leftover='' while f1.tell(): print f1.tell() if f1.tell()