Last active
August 29, 2015 14:07
-
-
Save mdshw5/14adbaaaf9e47f2d617d to your computer and use it in GitHub Desktop.
Assessment: Command-Line Programs
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 | |
import numpy | |
def main(): | |
script=sys.argv[0] | |
action=sys.argv[1] | |
filenames=sys.argv[2:] | |
assert action in ['--min", '--mean','--max'],\ | |
Action is not one of --min, --mean, or --max: ' + action | |
if len(filenames)==0 | |
process(sys.stdin,action) | |
else: | |
for f in filenames: | |
process(f,action) | |
def process(filename, action): | |
data=np.loadtxt(filename, delimiter=',') | |
if action == 'min': | |
values=data.min(axis=1) | |
elif action == 'mean': | |
values=data.mean(axis=1) | |
elif action == 'max': | |
values=data.max(axis=1) | |
for m in values: | |
print m | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment