# HG changeset patch # User Jeff Hammel # Date 1412724814 25200 # Node ID 1a0dfe551d714beea295a2faa4a2f4d6156d72e3 # Parent f4280845019972c7b3e727e9e8321ec9a86062b9 minor fixes/features diff -r f42808450199 -r 1a0dfe551d71 numerics/read.py --- 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()