Skip to content

Instantly share code, notes, and snippets.

@thomas-maschler
Last active August 31, 2016 17:03
Show Gist options
  • Save thomas-maschler/32c77c1f45989d38f56be0eb8e303000 to your computer and use it in GitHub Desktop.
Save thomas-maschler/32c77c1f45989d38f56be0eb8e303000 to your computer and use it in GitHub Desktop.
TSV
import csv
import glob
import os
csv_path = r"D:\temp\fires_tsv\csv\*"
csv_files = glob.glob(csv_path)
tsv_path = r"D:\temp\fires_tsv\tsv"
if not os.path.exists(tsv_path):
os.mkdir(tsv_path)
for csv_file in csv_files:
with open(csv_file) as c:
csv_basename = os.path.basename(csv_file)
print csv_basename
reader = csv.reader(c, delimiter=',', quotechar='"')
with open(os.path.join(tsv_path, os.path.splitext(csv_basename)[0] + ".tsv"), 'wb') as t:
writer = csv.writer(t, delimiter='\t', quotechar='"', quoting=csv.QUOTE_MINIMAL)
for row in reader:
writer.writerow(row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment