Skip to content

Instantly share code, notes, and snippets.

@niitsken
Last active June 27, 2016 02:30
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 niitsken/0b8bc0c1adee07a3e73aa4b71e4eb86f to your computer and use it in GitHub Desktop.
Save niitsken/0b8bc0c1adee07a3e73aa4b71e4eb86f to your computer and use it in GitHub Desktop.
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:
print
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment