Mercurial > hg > numerics
changeset 126:575c8e44227c
this should work and shit
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Mon, 16 Mar 2015 19:55:41 -0700 |
parents | d255058333b2 |
children | c9ae21955ca5 |
files | numerics/reduce.py |
diffstat | 1 files changed, 19 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/numerics/reduce.py Mon Mar 16 19:31:49 2015 -0700 +++ b/numerics/reduce.py Mon Mar 16 19:55:41 2015 -0700 @@ -15,13 +15,30 @@ __all__ = ['ReduceParser'] -class ReduceParser(argparse.ArgumentParser): +class ReduceParser(FloatParser): """CLI option parser""" + + # reducing function + function = lambda x: raise NotImplemented("Abstract base class") + def __init__(self, **kwargs): - kwargs.setdefault('formatter_class', argparse.RawTextHelpFormatter) kwargs.setdefault('description', __doc__) argparse.ArgumentParser.__init__(self, **kwargs) self.options = None + def __call__(self, *args): + # parse command line options + self.parse_args(args or sys.argv[1:]) + # read data + columns = self.typed_data() + if not columns: + self.error("No data given") + + # calculate scalars + data = [self.function(column) for column in column] + + # write CSV + writer = CSVWriter(options.output) + writer.write([data])