Project

General

Profile

« Previous | Next » 

Revision 5735

csvs.py: Added ColInsertFilter

View differences:

lib/csvs.py
160 160
        try: return self.reader.next()
161 161
        except StopIteration: return '' # EOF
162 162

  
163
class ColInsertFilter(Filter):
164
    '''Adds a column to each row
165
    @param mk_value(row, row_num)
166
    '''
167
    def __init__(self, reader, mk_value, index=0):
168
        def filter_(row):
169
            row = list(row) # make sure it's mutable; don't modify input!
170
            row.insert(index, mk_value(row, self.reader.line_num))
171
            return row
172
        Filter.__init__(self, filter_,
173
            streams.LineCountInputStream(StreamFilter(reader)))
174

  
163 175
class RowNumFilter(Filter):
164 176
    '''Adds a row # column at the beginning of each row'''
165 177
    def __init__(self, reader):

Also available in: Unified diff