# HG changeset patch # User Jeff Hammel # Date 1426561243 25200 # Node ID c9ae21955ca54b93e8c4fb6439927b99bdca415b # Parent 575c8e44227c2c513b2b43fcee91ffff6b504488 how to make this really small diff -r 575c8e44227c -r c9ae21955ca5 numerics/mean.py --- a/numerics/mean.py Mon Mar 16 19:55:41 2015 -0700 +++ b/numerics/mean.py Mon Mar 16 20:00:43 2015 -0700 @@ -8,30 +8,16 @@ # imports import sys from .filters import mean -from .manipulate import FloatParser -from .write import CSVWriter +from .reduce import ReduceParser + __all__ = ['main'] def main(args=sys.argv[1:]): """CLI""" - - # parse command line options - parser = FloatParser() - options = parser.parse_args(args) + ReduceParser(mean)(*args) - # read data - columns = parser.typed_data() - if not columns: - parser.error("No data given") - - # calculate means - means = [mean(column) for column in columns] - - # write CSV - writer = CSVWriter(options.output) - writer.write([means]) if __name__ == '__main__': main() diff -r 575c8e44227c -r c9ae21955ca5 numerics/reduce.py --- a/numerics/reduce.py Mon Mar 16 19:55:41 2015 -0700 +++ b/numerics/reduce.py Mon Mar 16 20:00:43 2015 -0700 @@ -18,13 +18,14 @@ class ReduceParser(FloatParser): """CLI option parser""" - # reducing function - function = lambda x: raise NotImplemented("Abstract base class") + def __init__(self, function, **kwargs): + """ + function -- reducing function + """ - def __init__(self, **kwargs): + self.function = function kwargs.setdefault('description', __doc__) - argparse.ArgumentParser.__init__(self, **kwargs) - self.options = None + FloatParser.__init__(self, **kwargs) def __call__(self, *args): @@ -37,8 +38,8 @@ self.error("No data given") # calculate scalars - data = [self.function(column) for column in column] + data = [self.function(column) for column in columns] # write CSV - writer = CSVWriter(options.output) + writer = CSVWriter(self.options.output) writer.write([data])