Skip to content

Instantly share code, notes, and snippets.

@youknowcast
Created June 30, 2019 05:20
Show Gist options
  • Save youknowcast/0db15243d1c492244fd58919b6197cb8 to your computer and use it in GitHub Desktop.
Save youknowcast/0db15243d1c492244fd58919b6197cb8 to your computer and use it in GitHub Desktop.
challenge1-2 nl.py
import sys
import os
args = sys.argv
if len(args) < 2:
print("usage python nl.py path/to/file")
exit()
path = args[1]
if os.path.exists(path) == False:
print("file not found.")
exit()
i = 1
f = open(path, 'r')
while True:
s = f.readline()
if not s: break
if len(s) == 1:
print(" \t")
else:
print("{:6d}\t{}".format(i, s[:-1]))
i += 1
#!/bin/bash
echo "test nl.py"
diff <(nl fizz_buzz.py) <(python nl.py fizz_buzz.py) | wc -l | awk '{$0 == 0 ? m = "ok" : m = "ng"} END {print m}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment