Skip to content

Instantly share code, notes, and snippets.

@guixing
Created August 25, 2013 02:33
Show Gist options
  • Save guixing/6331608 to your computer and use it in GitHub Desktop.
Save guixing/6331608 to your computer and use it in GitHub Desktop.
import sys
def readfilerev(fd):
buff = 256
fd.seek(0,2)
size = fd.tell()
rem = size % buff
pos = max(0, size - (buff + rem))
line = ''
while pos >= 0 :
fd.seek(pos, 0)
d = fd.read(buff+rem)
rem = 0
pos -= buff
if '\n' in d:
for c in reversed(d):
if c == '\n':
if line:
yield line
line = c
else:
line = c + line
else:
line = d+line
else:
yield line
for l in readfilerev(open(sys.argv[1])):
print l,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment