Source code for sgnlp.utils.csv_writer
import csv
[docs]class CsvWriter:
def __init__(self, file_path, fieldnames):
self.file_path = file_path
self.fieldnames = fieldnames
with open(file_path, "w") as f:
writer = self.get_writer(f)
writer.writeheader()
def get_writer(self, f):
return csv.DictWriter(f, fieldnames=self.fieldnames)
def writerow(self, row_dict):
with open(self.file_path, "a") as f:
writer = self.get_writer(f)
writer.writerow(row_dict)