Skip to content

Instantly share code, notes, and snippets.

@gka
Created September 16, 2011 12:20
Show Gist options
  • Save gka/1222000 to your computer and use it in GitHub Desktop.
Save gka/1222000 to your computer and use it in GitHub Desktop.
Converting a comma-separated and quoted file into a tab-separated and unquoted file
#!/usr/bin/env python2.7
"""
No more trouble with comma-separated and quoted CSV files.
"""
import csv, sys
if len(sys.argv) != 3: print 'Usage:\ncsv2tsv fromfile.csv tofile.tsv'
file_in = sys.argv[1]
file_out = sys.argv[2]
data = csv.reader(open(file_in, 'r'))
fout = open(file_out,'w')
out = csv.writer(fout, dialect='excel-tab')
for r in data: out.writerow(r)
fout.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment