From 8463fe6ead79aae75393388dde553bc1d5a56652 Mon Sep 17 00:00:00 2001 From: Tom Pollard Date: Wed, 3 Jul 2024 10:54:50 -0400 Subject: [PATCH] extract basename and remove extension with os.path.basename and os.path.splitext. --- wfdb/io/convert/csv.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/wfdb/io/convert/csv.py b/wfdb/io/convert/csv.py index fc75b5ba..b4114872 100644 --- a/wfdb/io/convert/csv.py +++ b/wfdb/io/convert/csv.py @@ -325,16 +325,14 @@ def csv_to_wfdb( print("Signal names: {}".format(sig_name)) # Determine the output directory + base_name = os.path.splitext(os.path.basename(file_name))[0] + if write_dir: if not os.path.exists(write_dir): os.makedirs(write_dir) - output_base = os.path.join( - write_dir, os.path.basename(file_name).replace(".csv", "") - ) + output_base = os.path.join(write_dir, base_name) else: - if os.sep in file_name: - file_name = file_name.split(os.sep)[-1] - output_base = file_name.replace(".csv", "") + output_base = base_name if verbose: print("Output base: {}".format(output_base))