Last active
June 27, 2016 02:30
-
-
Save niitsken/0b8bc0c1adee07a3e73aa4b71e4eb86f 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 | |
args = len(sys.argv) | |
if args == 1: | |
print("Enter a file name below") | |
f = sys.stdin.readline().rstrip() | |
elif args == 2: | |
f = sys.argv[1] | |
else: | |
sys.exit("please enter the command this way: 'python nl.py [a file]'") | |
try: | |
f = open(f, "rU") | |
except IOError: | |
sys.exit("%s: No such a file or directory" % (f)) | |
i = 1 | |
for s in f: | |
s = s.rstrip() | |
if s: | |
print "%5d\t%s" % (i, s) | |
i += 1 | |
else: | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment