Skip to content

Commit

Permalink
Adds encoding settings to read and write function
Browse files Browse the repository at this point in the history
  • Loading branch information
dkuschmierz committed Jan 17, 2024
1 parent 10a1412 commit b75645d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = dcmReader
version = 0.4.0
version = 0.4.1
author = Dominic Kuschmierz
author_email = [email protected]
description = Parser for the DCM (Data Conservation format) format used by e.g. Vector, ETAS,...
Expand Down
8 changes: 4 additions & 4 deletions src/dcmReader/dcm_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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()
Expand Down

0 comments on commit b75645d

Please sign in to comment.