-
-
Save yehudalev/e554474759551df9f42536f029e2581f 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 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