# HG changeset patch # User Jeff Hammel # Date 1470778471 25200 # Node ID 69543d62ae7a672142dce68dcc320bfc729e1017 # Parent f63194f81f7d5df4928ef06572a0d682330ce600 more split stubbing diff -r f63194f81f7d -r 69543d62ae7a numerics/split_table.py --- a/numerics/split_table.py Tue Aug 09 14:03:33 2016 -0700 +++ b/numerics/split_table.py Tue Aug 09 14:34:31 2016 -0700 @@ -5,6 +5,8 @@ """ # imports +import argparse +import csv import chunk import sys import table @@ -34,7 +36,12 @@ # read CSV data = parser.read_table() - print 'hi' + header = data[0].keys() + + for index, row in enumerate(data): + print '{index}'.format(index=index) + + output_data = [list(header)] if __name__ == '__main__': main() diff -r f63194f81f7d -r 69543d62ae7a numerics/table.py --- a/numerics/table.py Tue Aug 09 14:03:33 2016 -0700 +++ b/numerics/table.py Tue Aug 09 14:34:31 2016 -0700 @@ -12,6 +12,7 @@ import os import sys import time +from collections import OrderedDict string = (str, unicode) @@ -56,7 +57,7 @@ duplicate_fields = duplicates(*header) if duplicate_fields: raise AssertionError("Duplicate header fields found: {duplicates}".format(duplicates=', '.join(duplicate_fields))) - return [dict(zip(header, row)) + return [OrderedDict(zip(header, row)) for row in data] @@ -100,16 +101,18 @@ data = read_table(self.options.input, verbose=self.options.verbose) - + if not data: + parser.error("No data found: {}".format(self.options.intput)) if self.options.columns: + header = data[0].keys() missing = [column for column in self.options.columns if column not in header] if missing: self.error("Columns not found in header: {0}".format(", ".join(missing))) header = options.columns - data = [dict(zip(header, - [row[column] for column in header])) + data = [OrderedDict(zip(header, + [row[column] for column in header])) for row in data] return data