Skip to content

Instantly share code, notes, and snippets.

@j-min
Forked from solidpple/CSVFileIO.py
Created November 17, 2016 02:01
Show Gist options
  • Save j-min/c4ff90487a4fba0a0282b7373415ee06 to your computer and use it in GitHub Desktop.
Save j-min/c4ff90487a4fba0a0282b7373415ee06 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