changeset 26:4c9ade74c4d7 draft

Uploaded
author luca_milaz
date Thu, 19 Sep 2024 08:13:29 +0000
parents 80bfd8743ea6
children b61fc7f1b6ab
files COBRAxy/custom_data_generator.py
diffstat 1 files changed, 20 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/COBRAxy/custom_data_generator.py	Thu Sep 19 08:06:59 2024 +0000
+++ b/COBRAxy/custom_data_generator.py	Thu Sep 19 08:13:29 2024 +0000
@@ -145,7 +145,7 @@
 
 
 ###############################- FILE SAVING -################################
-def save_as_csv(data :dict, file_path :utils.FilePath, fieldNames :Tuple[str, str]) -> None:
+def save_as_csv_filePath(data :dict, file_path :utils.FilePath, fieldNames :Tuple[str, str]) -> None:
     """
     Saves any dictionary-shaped data in a .csv file created at the given file_path.
 
@@ -164,6 +164,25 @@
         for key, value in data.items():
             writer.writerow({ fieldNames[0] : key, fieldNames[1] : value })
 
+def save_as_csv(data :dict, file_path :str, fieldNames :Tuple[str, str]) -> None:
+    """
+    Saves any dictionary-shaped data in a .csv file created at the given file_path.
+
+    Args:
+        data : the data to be written to the file.
+        file_path : the path to the .csv file.
+        fieldNames : the names of the fields (columns) in the .csv file.
+    
+    Returns:
+        None
+    """
+    with open(file_path, 'w', newline='') as csvfile:
+        writer = csv.DictWriter(csvfile, fieldnames = fieldNames, dialect="excel-tab")
+        writer.writeheader()
+
+        for key, value in data.items():
+            writer.writerow({ fieldNames[0] : key, fieldNames[1] : value })
+
 ###############################- ENTRY POINT -################################
 def main() -> None:
     """