This commit is contained in:
M. A. Reza 2025-11-18 15:45:41 +03:30
parent d6892e0f08
commit dc2750d185

View File

@ -24,11 +24,17 @@ def write_to_csv_file(rows, file_path: Path, rows_type, fieldnames=None):
raise Exception("rows_type value is invalid!")
def append_to_csv_file(rows, file_path: Path):
def append_to_csv_file(rows, file_path: Path, rows_type, fieldnames=None):
file_path.parent.mkdir(parents=True, exist_ok=True)
with open(file_path, mode="a", newline="") as csvfile:
csv_writer = csv.writer(csvfile)
return csv_writer.writerows(rows)
if rows_type is list:
csv_writer = csv.writer(csvfile)
return csv_writer.writerows(rows)
elif rows_type is dict:
csv_writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
csv_writer.writerows(rows)
else:
raise Exception("rows_type value is invalid!")
def convert_config_to_key_val_dict(config: list):