Mercurial > hg > numerics
annotate numerics/manipulate.py @ 125:d255058333b2
putzing
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Mon, 16 Mar 2015 19:31:49 -0700 |
parents | c4d26ef63d8e |
children | 12649a88545c |
rev | line source |
---|---|
57 | 1 #!/usr/bin/env python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 manipulate CSV data | |
6 """ | |
7 | |
8 # imports | |
9 import argparse | |
10 import os | |
11 import sys | |
108 | 12 from .convert import default_cast, cast_columns |
110 | 13 from .data import transpose |
60 | 14 from .read import CSVParser |
57 | 15 |
16 # module globals | |
125 | 17 __all__ = ['ManipulationParser', 'FloatParser', 'main'] |
110 | 18 |
57 | 19 |
60 | 20 class ManipulationParser(CSVParser): |
21 """CLI option parser for data manipulation""" | |
22 | |
108 | 23 types = default_cast |
24 | |
57 | 25 def __init__(self, **kwargs): |
26 kwargs.setdefault('description', __doc__) | |
60 | 27 CSVParser.__init__(self, **kwargs) |
57 | 28 self.options = None |
29 | |
60 | 30 def typed_data(self): |
108 | 31 """return parsed and casted data""" |
110 | 32 return cast_columns(self.columns(), self.types) |
33 | |
34 def process(self): | |
35 return transpose(self.typed_data()) | |
57 | 36 |
111
c4d26ef63d8e
fix error in convert and i think this works sorta well enouigh for now
Jeff Hammel <k0scist@gmail.com>
parents:
110
diff
changeset
|
37 |
125 | 38 class FloatParser(ManipulationParser): |
39 """manipulation parser convenience just for floats""" | |
40 types = (float,) | |
41 | |
42 | |
57 | 43 def main(args=sys.argv[1:]): |
44 """CLI""" | |
45 | |
46 # parse command line options | |
106 | 47 parser = ManipulationParser() |
57 | 48 options = parser.parse_args(args) |
49 | |
110 | 50 # write manipulated data |
51 parser.write(parser.process()) | |
52 | |
57 | 53 if __name__ == '__main__': |
54 main() |