Created
August 25, 2013 02:43
-
-
Save archerslaw/6331658 to your computer and use it in GitHub Desktop.
sibiaoluo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
#coding:utf-8 | |
import re | |
import sys | |
import os | |
def filerev(somefile, buffer=256): | |
somefile.seek(0, os.SEEK_END) | |
size = somefile.tell() | |
lines = [''] | |
rem = size % buffer | |
pos = max(0, (size // buffer - 1) * buffer) | |
while pos >= 0: | |
somefile.seek(pos, os.SEEK_SET) | |
data = somefile.read(rem + buffer) + lines[0] | |
rem = 0 | |
pos -= buffer | |
lines = re.findall(r'[^\n]*\n?', data) | |
ix = len(lines) - 2 | |
while ix > 0: | |
yield lines[ix] | |
ix -= 1 | |
else: | |
yield lines[0] | |
with open(sys.argv[1], 'r') as f: | |
for line in filerev(f): | |
sys.stdout.write(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment