-
-
Save gsathya/1622002 to your computer and use it in GitHub Desktop.
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
import sys | |
import linecache | |
import os | |
if os.path.isfile(sys.argv[1]): | |
try: | |
with open(sys.argv[1], 'r') as f: | |
content = f.readlines() | |
length = len(content) | |
except IOError as e: | |
print 'File does not exist' | |
isFile = True | |
else: | |
f = sys.stdin | |
g = f.readlines() | |
length = len(g) | |
isFile = False | |
if isFile: | |
if int(sys.argv[2]) >= 0: | |
myArg = int(sys.argv[2]) | |
else: | |
myArg = 5 | |
mark = length - myArg + 1 | |
for i in range(mark, length+1): | |
sys.stdout.write(linecache.getline(sys.argv[1], i)) | |
else: | |
if int(sys.argv[1]) >= 0: | |
myArg = int(sys.argv[1]) | |
else: | |
myArg = 5 | |
mark = length - myArg | |
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