Commit 46ce1b1 1 parent e1046d9 commit 46ce1b1 Copy full SHA for 46ce1b1
File tree 1 file changed +5
-1
lines changed
1 file changed +5
-1
lines changed Original file line number Diff line number Diff line change @@ -19,16 +19,20 @@ class CSVWriter(Writer):
19
19
'translations' ,
20
20
]
21
21
22
- def __init__ (self , file_name : str ):
22
+ def __init__ (self , file_name : str , write_header : bool = False ):
23
23
super ().__init__ ()
24
24
self .__file_name = file_name
25
+ self .__write_header = write_header
25
26
26
27
def write (self , data : Dict [str , List [WordDefinition ]]):
27
28
print ("writing to csv, total {} words..." .format (len (data )))
28
29
29
30
with open (self .__file_name , 'w' , newline = '' ) as csv_file :
30
31
writer = csv .DictWriter (csv_file , fieldnames = self .__field_names )
31
32
33
+ if self .__write_header :
34
+ writer .writeheader ()
35
+
32
36
word : str
33
37
for word in data .keys ():
34
38
definition : WordDefinition = data [word ][0 ] if len (data [word ]) > 0 else []
You can’t perform that action at this time.
0 commit comments