Skip to content

Instantly share code, notes, and snippets.

@mdshw5
Last active August 29, 2015 14:07
Show Gist options
  • Save mdshw5/14adbaaaf9e47f2d617d to your computer and use it in GitHub Desktop.
Save mdshw5/14adbaaaf9e47f2d617d to your computer and use it in GitHub Desktop.
Assessment: Command-Line Programs
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