changeset 25:1a0dfe551d71

minor fixes/features
author Jeff Hammel <k0scist@gmail.com>
date Tue, 07 Oct 2014 16:33:34 -0700
parents f42808450199
children e01d84d29cd0
files numerics/read.py
diffstat 1 files changed, 15 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/numerics/read.py	Tue Oct 07 16:05:55 2014 -0700
+++ b/numerics/read.py	Tue Oct 07 16:33:34 2014 -0700
@@ -100,6 +100,11 @@
         argparse.ArgumentParser.__init__(self, **kwargs)
         self.add_argument('csv', nargs='+',
                           help="CSV files to read")
+        self.add_argument('-+', '--add', dest='added_columns', nargs='+',
+                          help="append this column")
+        self.add_argument('-o', '--output', dest='output',
+                          type=argparse.FileType('a'), default=sys.stdout,
+                          help='output destination, or stdout')
         self.options = None
 
     def parse_args(self, *args, **kw):
@@ -120,8 +125,16 @@
 
     # read CSV
     data = read_csv(*options.csv)
-    from pprint import pprint
-    pprint(data)
+
+    if options.added_columns:
+        # add columns
+        for row in data:
+            row.extend(options.added_columns)
+
+    # write CSV
+    writer = csv.writer(options.output)
+    for row in data:
+        writer.writerow(row)
 
 if __name__ == '__main__':
     main()