Revision 7290
Added by Aaron Marcuse-Kubitza almost 12 years ago
lib/csvs.py | ||
---|---|---|
166 | 166 |
except StopIteration: return '' # EOF |
167 | 167 |
|
168 | 168 |
class ColInsertFilter(Filter): |
169 |
'''Adds a column to each row
|
|
169 |
'''Adds column(s) to each row
|
|
170 | 170 |
@param mk_value(row, row_num) |
171 | 171 |
''' |
172 |
def __init__(self, reader, mk_value, index=0): |
|
172 |
def __init__(self, reader, mk_value, index=0, n=1):
|
|
173 | 173 |
def filter_(row): |
174 | 174 |
row = list(row) # make sure it's mutable; don't modify input! |
175 |
row.insert(index, mk_value(row, self.reader.line_num)) |
|
175 |
for i in xrange(n): |
|
176 |
row.insert(index+i, mk_value(row, self.reader.line_num)) |
|
176 | 177 |
return row |
177 | 178 |
Filter.__init__(self, filter_, |
178 | 179 |
streams.LineCountInputStream(StreamFilter(reader))) |
Also available in: Unified diff
csvs.py: ColInsertFilter: Support adding multiple, consecutive columns