Monday, December 12, 2011

Convert CSV to TSV

import csv
open("output.tsv", "w").write("\n".join("\t".join(e.strip() for e in i) for i in csv.reader(open("input.csv"))))

2 comments:

void said...

You've almost caught it:

csv.writer(file('output.tsv', 'w+'), delimiter='\t').writerows(csv.reader(open("input.csv")))

Simon Wittber said...

Oh yeah, much better! :)

Popular Posts