added new csv mixin for writing a set of lines to a file.
This commit is contained in:
parent
f93e20b529
commit
b816b1de49
19
artifice/csv_mixin.py
Normal file
19
artifice/csv_mixin.py
Normal 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()
|
Loading…
x
Reference in New Issue
Block a user