From b75645df51908e385f626615ad01f812a1c1b8aa Mon Sep 17 00:00:00 2001 From: Dominic Kuschmierz Date: Wed, 17 Jan 2024 21:09:08 +0100 Subject: [PATCH] Adds encoding settings to read and write function --- setup.cfg | 2 +- src/dcmReader/dcm_reader.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/setup.cfg b/setup.cfg index ae22d85..a854cae 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = dcmReader -version = 0.4.0 +version = 0.4.1 author = Dominic Kuschmierz author_email = dominic@kuschmierz.org description = Parser for the DCM (Data Conservation format) format used by e.g. Vector, ETAS,... diff --git a/src/dcmReader/dcm_reader.py b/src/dcmReader/dcm_reader.py index 8dfeac4..3c1f44c 100644 --- a/src/dcmReader/dcm_reader.py +++ b/src/dcmReader/dcm_reader.py @@ -103,7 +103,7 @@ def convert_value(value): except ValueError as err: raise ValueError(f"Cannot convert {value} from string to number.") from err - def write(self, file) -> None: + def write(self, file, file_encoding="utf-8") -> None: """Writes the current DCM object to a dcm file Args: @@ -112,10 +112,10 @@ def write(self, file) -> None: if not file.endswith(".dcm"): file += ".dcm" - with open(file, "w", encoding="utf-8") as dcm_file: + with open(file, "w", encoding=file_encoding) as dcm_file: dcm_file.writelines(str(self)) - def read(self, file) -> None: + def read(self, file, file_encoding="utf-8") -> None: """Reads and processes the given file. Args: @@ -125,7 +125,7 @@ def read(self, file) -> None: comment_qualifier = ("!", "*", ".") - with open(file, "r", encoding="utf-8") as dcm_file: + with open(file, "r", encoding=file_encoding) as dcm_file: for line in dcm_file: # Remove whitespaces line = line.strip()