| 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