Mercurial > hg > numerics
annotate numerics/manipulate.py @ 111:c4d26ef63d8e
fix error in convert and i think this works sorta well enouigh for now
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sun, 15 Mar 2015 15:38:12 -0700 |
parents | 5790bcb30bd8 |
children | d255058333b2 |
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 | |
106 | 17 __all__ = ['ManipulationParser', '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 |
57 | 38 def main(args=sys.argv[1:]): |
39 """CLI""" | |
40 | |
41 # parse command line options | |
106 | 42 parser = ManipulationParser() |
57 | 43 options = parser.parse_args(args) |
44 | |
110 | 45 # write manipulated data |
46 parser.write(parser.process()) | |
47 | |
57 | 48 if __name__ == '__main__': |
49 main() |