Skip to content

Commit

Permalink
csvlook: Fix "underlying stream is not seekable" when piping input
Browse files Browse the repository at this point in the history
  • Loading branch information
James McKinney committed Jun 23, 2016
1 parent 841600f commit c32228d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions csvkit/utilities/csvlook.py
@@ -1,6 +1,9 @@
#!/usr/bin/env python

import sys

import agate
import six

from csvkit.cli import CSVKitUtility

Expand All @@ -21,6 +24,11 @@ def add_arguments(self):
help='Disable type inference when parsing the input.')

def main(self):
# Otherwise, fails with "io.UnsupportedOperation: underlying stream is not seekable".
if self.input_file == sys.stdin:
# We can't sort without reading the entire input.
self.input_file = six.StringIO(sys.stdin.read())

table = agate.Table.from_csv(self.input_file, sniff_limit=self.args.sniff_limit, header=not self.args.no_header_row, column_types=self.get_column_types(), line_numbers=self.args.line_numbers, **self.reader_kwargs)
table.print_table(output=self.output_file, max_rows=self.args.max_rows, max_columns=self.args.max_columns, max_column_width=self.args.max_column_width)

Expand Down

0 comments on commit c32228d

Please sign in to comment.