Skip to content

fields don't work #13

@lk-jeffpeck

Description

@lk-jeffpeck
$ csvfilter -f 1,2,3 file.csv

Expected:
Output columns 1, 2, and 3 from file.csv for all rows

Actual:
Only outputs columns 1, 2, and 3 from the first row.


It looks like the reason for this is:

fields = map(int, options.fields.split(',')) if options.fields else None

... which is being consumed after the first row:

output = [row[i] for i in self.fields if len(row) > i]

after which self.fields becomes an empty array: []

A solution would be:

fields = list(map(int, options.fields.split(','))) if options.fields else None

This PR should resolve:
#12

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions