Mercurial > hg > numerics
changeset 30:75270e7a051b
add ability to add an index and fix a few bugs
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Tue, 04 Nov 2014 14:54:10 -0800 |
parents | c2c92c8da611 |
children | a655306ee78d |
files | numerics/read.py |
diffstat | 1 files changed, 11 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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)