-
-
Save j-min/c4ff90487a4fba0a0282b7373415ee06 to your computer and use it in GitHub Desktop.
This file contains 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
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