Last active
July 8, 2021 17:59
-
-
Save ragnarheidar/89563c531a15aa5c3f5e to your computer and use it in GitHub Desktop.
A python script that reads a CSV file and writes it out with a different delimiter.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import csv | |
from tempfile import NamedTemporaryFile | |
import shutil | |
readfile = "SOME\\PATH\\input.csv" | |
writefile = "SOME\\PATH\\output.csv" | |
tempfile = NamedTemporaryFile(delete=False) | |
with open(readfile, 'rb') as csvfilein, tempfile: | |
reader = csv.reader(csvfilein, delimiter='|', quotechar='"') | |
writer = csv.writer(tempfile, delimiter=';', quotechar='"') | |
for row in reader: | |
writer.writerow(row) | |
shutil.move(tempfile.name, writefile) | |
print "done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment