diff options
| author | Alexander_Kabui | 2025-01-23 15:32:42 +0300 |
|---|---|---|
| committer | BonfaceKilz | 2025-02-06 12:43:15 +0300 |
| commit | 0bdf80ee7d319869b0057f30712f69a312435815 (patch) | |
| tree | a44f9bec4d403b76b722aa1018157c8188f22a7b /gn3/computations/rqtl2.py | |
| parent | 5610bad55bd27762384ec5d4c253dc0772e9b4c6 (diff) | |
| download | genenetwork3-0bdf80ee7d319869b0057f30712f69a312435815.tar.gz | |
refactor: Check if data before attempting write operation.
Diffstat (limited to 'gn3/computations/rqtl2.py')
| -rw-r--r-- | gn3/computations/rqtl2.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/gn3/computations/rqtl2.py b/gn3/computations/rqtl2.py index 0d60ec0..17e77d6 100644 --- a/gn3/computations/rqtl2.py +++ b/gn3/computations/rqtl2.py @@ -30,9 +30,11 @@ def write_to_csv(work_dir, file_name, data:list[dict], """Functions to write data list to csv file if headers is not provided use the keys for first boject. """ - file_path = os.path.join(work_dir, file_name) - if headers is None and data: + if not data: + return + if headers is None: headers = data[0].keys() + file_path = os.path.join(work_dir, file_name) with open(file_path, "w", encoding="utf-8") as file_handler: writer = csv.DictWriter(file_handler, fieldnames=headers, delimiter=delimiter) @@ -72,7 +74,7 @@ def create_file(file_path): """Utility function to create file given a file_path""" try: with open(file_path, "x",encoding="utf-8") as _file_handler: - return True, "File created at" + return True, f"File created at {file_path}" except FileExistsError: return False, "File Already Exists" |
