Skip to content

Commit 46ce1b1

Browse files
committed
Add write header parameter for CSV writer
1 parent e1046d9 commit 46ce1b1

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

writers/csv_writer.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,20 @@ class CSVWriter(Writer):
1919
'translations',
2020
]
2121

22-
def __init__(self, file_name: str):
22+
def __init__(self, file_name: str, write_header: bool = False):
2323
super().__init__()
2424
self.__file_name = file_name
25+
self.__write_header = write_header
2526

2627
def write(self, data: Dict[str, List[WordDefinition]]):
2728
print("writing to csv, total {} words...".format(len(data)))
2829

2930
with open(self.__file_name, 'w', newline='') as csv_file:
3031
writer = csv.DictWriter(csv_file, fieldnames=self.__field_names)
3132

33+
if self.__write_header:
34+
writer.writeheader()
35+
3236
word: str
3337
for word in data.keys():
3438
definition: WordDefinition = data[word][0] if len(data[word]) > 0 else []

0 commit comments

Comments
 (0)