Mercurial > hg > numerics
annotate numerics/manipulate.py @ 135:12649a88545c
stubbing: hooking this up to command line
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Tue, 17 Mar 2015 11:53:33 -0700 |
parents | d255058333b2 |
children | cffa11cb91a0 |
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 |
135
12649a88545c
stubbing: hooking this up to command line
Jeff Hammel <k0scist@gmail.com>
parents:
125
diff
changeset
|
15 from .sort import Sorter |
57 | 16 |
17 # module globals | |
125 | 18 __all__ = ['ManipulationParser', 'FloatParser', 'main'] |
110 | 19 |
57 | 20 |
60 | 21 class ManipulationParser(CSVParser): |
22 """CLI option parser for data manipulation""" | |
23 | |
108 | 24 types = default_cast |
25 | |
57 | 26 def __init__(self, **kwargs): |
27 kwargs.setdefault('description', __doc__) | |
60 | 28 CSVParser.__init__(self, **kwargs) |
57 | 29 self.options = None |
30 | |
60 | 31 def typed_data(self): |
108 | 32 """return parsed and casted data""" |
110 | 33 return cast_columns(self.columns(), self.types) |
34 | |
35 def process(self): | |
36 return transpose(self.typed_data()) | |
57 | 37 |
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
|
38 |
125 | 39 class FloatParser(ManipulationParser): |
40 """manipulation parser convenience just for floats""" | |
41 types = (float,) | |
42 | |
43 | |
57 | 44 def main(args=sys.argv[1:]): |
45 """CLI""" | |
46 | |
47 # parse command line options | |
106 | 48 parser = ManipulationParser() |
57 | 49 options = parser.parse_args(args) |
50 | |
110 | 51 # write manipulated data |
52 parser.write(parser.process()) | |
53 | |
57 | 54 if __name__ == '__main__': |
55 main() |