added new csv mixin for writing a set of lines to a file.

This commit is contained in:
adrian 2013-12-03 14:41:33 +13:00
parent f93e20b529
commit b816b1de49

19
artifice/csv_mixin.py Normal file
View File

@ -0,0 +1,19 @@
from csv import writer
class CSV_File_mixin(object):
def write_output(self):
try:
read = open(self.filename)
raise RuntimeError("Can't write to an existing file!")
except IOError:
pass
fh = open(self.filename, "w")
csvwriter = writer(fh, dialect='excel', delimiter=',')
for line in self.lines:
# Line is expected to be an iterable row
csvwriter.writerow(line)
fh.close()