# HG changeset patch # User Jeff Hammel # Date 1415141650 28800 # Node ID 75270e7a051b48d10bf980e23e1c9d68a3213b39 # Parent c2c92c8da61132cba7333e6068046b4b9c05dc86 add ability to add an index and fix a few bugs diff -r c2c92c8da611 -r 75270e7a051b numerics/read.py --- a/numerics/read.py Thu Oct 09 15:01:01 2014 -0700 +++ b/numerics/read.py Tue Nov 04 14:54:10 2014 -0800 @@ -99,6 +99,9 @@ self.add_argument('-o', '--output', dest='output', type=argparse.FileType('a'), default=sys.stdout, help='output destination, or stdout') + self.add_argument('--index', dest='index', + action='store_true', default=False, + help="prepend each row with numeric index") self.options = None def parse_args(self, *args, **kw): @@ -126,8 +129,14 @@ row.extend(options.added_columns) if options.columns: - rows = [[row[column] for column in options[columns]] - for row in rows] + # filter by column + data = [[row[column] for column in options.columns] + for row in data] + + if options.index: + # prepend numeric index + for index, row in enumerate(data): + row.insert(0, index) # write CSV writer = csv.writer(options.output)