Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 39 lines (32 sloc) 1.08 KB
#!/usr/bin/env python
Input is Excel-style CSV. Either stdin or filename.
(We can handle Mac Excel's \r-delimited csv)
Output is honest-to-goodness tsv: no quoting or any \n\r\t.
#from __future__ import print_function
import csv, sys
from tsvutil import cell_text_clean, warning, UnicodeReader
def clean_row(row):
return [cell_text_clean(x) for x in row]
args = sys.argv[:]
if len(args)==1:
reader = csv.reader(open(args[0],'U'))
#reader = csv.reader([0],'U','utf-8'))
elif len(args) > 1:
raise Exception("No support for multiple files yet")
# could try to enforce conformity, or meld them together, etc.
elif not sys.stdin.isatty():
reader = csv.reader(sys.stdin)
header =
print "\t".join(clean_row(header)).encode('utf8')
#print(*clean_row(header), sep="\t")
for row in reader:
if len(row) < len(header):
# warning("Row with %d values is too short; padding with %d blanks" % (len(row),len(header)-len(row)))
row += [''] * (len(header) - len(row))
print "\t".join(clean_row(row))