Skip to content

Commit

Permalink
pass kwargs to dict writer
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhsingh971 committed Dec 30, 2023
1 parent 97d09db commit 263c769
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pyutils/csvu/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def load_csv(
return data


def save_csv(file_path, rows, mode, fieldnames=None):
def save_csv(file_path, rows, mode, fieldnames=None, **dict_writer_kwargs):
logger.debug("Saving csv file: {}, rows: {}".format(file_path, len(rows)))
if not rows:
return
Expand All @@ -108,7 +108,7 @@ def save_csv(file_path, rows, mode, fieldnames=None):
os.makedirs(parent_dir)
write_header = True
with open(file_path, mode) as fp:
writer = csv.DictWriter(fp, fieldnames=fieldnames or rows[0].keys())
writer = csv.DictWriter(fp, fieldnames=fieldnames or rows[0].keys(), **dict_writer_kwargs)
if write_header:
writer.writeheader()
writer.writerows(rows)

0 comments on commit 263c769

Please sign in to comment.