Skip to content

Instantly share code, notes, and snippets.

@tmaybe
Last active September 27, 2016 20:30
Show Gist options
  • Save tmaybe/8931979 to your computer and use it in GitHub Desktop.
Save tmaybe/8931979 to your computer and use it in GitHub Desktop.
strip quoted newlines from a folder-full of CSV files
import csv
import re
import glob
for input_filename in glob.glob("./*.csv"):
print("working on {}".format(input_filename))
with open(input_filename, 'rU') as infile:
output_filename = "./strp-{}.csv".format(input_filename.lower().rstrip(".csv").lstrip("./"))
with open(output_filename, 'a') as outfile:
output_writer = csv.writer(outfile)
for input_row in csv.reader(infile):
for input_pos in range(len(input_row)):
input_row[input_pos] = re.sub('\n', ' ', input_row[input_pos])
output_writer.writerow(input_row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment