Skip to content

Commit

Permalink
Use DictWriter instead of plain loop
Browse files Browse the repository at this point in the history
  • Loading branch information
AliOsm committed Aug 25, 2023
1 parent f47546a commit a4fc6b3
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions tafrigh/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,9 @@ def write_csv(
delimiter=',',
) -> None:
with open(file_path, 'w', encoding='utf-8') as fp:
writer = csv.writer(fp, delimiter=delimiter)
writer.writerow(['text', 'start', 'end'])

for segment in segments:
writer.writerow([segment['text'], segment['start'], segment['end']])
writer = csv.DictWriter(fp, fieldnames=['text', 'start', 'end'], delimiter=delimiter)
writer.writeheader()
writer.writerows(segments)

def write_json(
self,
Expand Down

0 comments on commit a4fc6b3

Please sign in to comment.