Created
January 14, 2012 20:19
-
-
Save shadeslayer/1612744 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import sys | |
import linecache | |
import os | |
if os.path.isfile(sys.argv[1]): | |
try: | |
f = open(sys.argv[1], 'r') | |
except IOError as e: | |
print 'File does not exist' | |
isFile = True | |
else: | |
f = sys.stdin | |
g = f.readlines() | |
isFile = False | |
#optimize for memory | |
length = 0 | |
for line in f: | |
length += 1 | |
f.close() | |
if isFile: | |
mark = length - abs(int(sys.argv[2])) + 1 | |
for i in range(mark, length+1): | |
sys.stdout.write(linecache.getline(sys.argv[1], i)) | |
else: | |
mark = length - abs(int(sys.argv[1])) | |
for i in range(mark, length + 1): | |
sys.stdout.write(g[i]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment