Skip to content

Instantly share code, notes, and snippets.

@solidpple
Created August 11, 2016 05:33
Show Gist options
  • Save solidpple/cad1924b16b47bbd826afac6c5399aab to your computer and use it in GitHub Desktop.
Save solidpple/cad1924b16b47bbd826afac6c5399aab to your computer and use it in GitHub Desktop.
import csv
import os
def get_csv_writer(filename, rows, delimiter):
with open(filename, 'w') as csvfile:
fieldnames = rows[0].keys()
writer = csv.DictWriter(csvfile, fieldnames=fieldnames, delimiter=delimiter)
writer.writeheader()
for row in rows:
try:
writer.writerow(row)
except Exception as detail:
print type(detail)
print detail
def get_csv_reader(filename, delimiter):
reader = []
if not os.path.isfile(filename):
csvfile = open(filename, "w")
else:
csvfile = open(filename, "rb")
reader = csv.DictReader(csvfile, delimiter=delimiter)
return list(reader)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment