Last active
August 29, 2015 14:23
-
-
Save michitomo/fcd5a9bdd133343fd6ac to your computer and use it in GitHub Desktop.
課題1‐2: Unixのnlコマンドの基本機能相当のnl.pyを書いてください。
This file contains hidden or 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 | |
if len(sys.argv) > 1: | |
try: | |
f = open(sys.argv[1], "rU") | |
except IOError: | |
print "File" + sys.argv[1] + "not found" | |
sys.exit(1) | |
else: | |
f = sys.stdin | |
lines = f.readlines() | |
for (i, line) in enumerate(lines): | |
print str(i) + line, | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment