Skip to content

Instantly share code, notes, and snippets.

@shadeslayer
Created January 14, 2012 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save shadeslayer/1612744 to your computer and use it in GitHub Desktop.
Save shadeslayer/1612744 to your computer and use it in GitHub Desktop.
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