From 7d2313656d0ad700f29ddddb7d7d048d9d9c4535 Mon Sep 17 00:00:00 2001 From: Marko Toplak Date: Tue, 6 Feb 2024 13:57:48 +0100 Subject: [PATCH] Explicitely define utf8 encoding on open() --- orangecontrib/spectroscopy/io/maxiv.py | 2 +- orangecontrib/spectroscopy/io/neaspec.py | 6 +++--- orangecontrib/spectroscopy/io/soleil.py | 2 +- orangecontrib/spectroscopy/utils/spc/spc.py | 2 +- setup.py | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/orangecontrib/spectroscopy/io/maxiv.py b/orangecontrib/spectroscopy/io/maxiv.py index 7387a428b..7f8e4115a 100644 --- a/orangecontrib/spectroscopy/io/maxiv.py +++ b/orangecontrib/spectroscopy/io/maxiv.py @@ -85,7 +85,7 @@ def read_hdr_dict(self, inner=True): assert self._lex.get_token() == ';' def read_spectra(self): - with open(self.filename, 'r') as f: + with open(self.filename, 'rt', encoding="utf8") as f: # Parse file contents into dictionaries/lists self._lex = shlex.shlex(instream=f) try: diff --git a/orangecontrib/spectroscopy/io/neaspec.py b/orangecontrib/spectroscopy/io/neaspec.py index 2cf0c5704..c55835024 100644 --- a/orangecontrib/spectroscopy/io/neaspec.py +++ b/orangecontrib/spectroscopy/io/neaspec.py @@ -16,7 +16,7 @@ class NeaReader(FileFormat, SpectralFileFormat): def read_v1(self): - with open(self.filename, "rt") as f: + with open(self.filename, "rt", encoding="utf8") as f: next(f) # skip header l = next(f) l = l.strip() @@ -120,7 +120,7 @@ def read_v2(self): # Find line in which data begins count = 0 - with open(self.filename, "r") as f: + with open(self.filename, "rt", encoding="utf8") as f: while f: line = f.readline() count = count + 1 @@ -185,7 +185,7 @@ def read_v2(self): def read_spectra(self): version = 1 - with open(self.filename, "rt") as f: + with open(self.filename, "rt", encoding="utf8") as f: if f.read(2) == '# ': version = 2 if version == 1: diff --git a/orangecontrib/spectroscopy/io/soleil.py b/orangecontrib/spectroscopy/io/soleil.py index 9409b16f6..7ede84081 100644 --- a/orangecontrib/spectroscopy/io/soleil.py +++ b/orangecontrib/spectroscopy/io/soleil.py @@ -14,7 +14,7 @@ class SelectColumnReader(FileFormat, SpectralFileFormat): @property def sheets(self): - with open(self.filename, 'r') as dataf: + with open(self.filename, 'rt', encoding="utf8") as dataf: l = "" for l in dataf: if not l.startswith('#'): diff --git a/orangecontrib/spectroscopy/utils/spc/spc.py b/orangecontrib/spectroscopy/utils/spc/spc.py index 0baadca4b..641251ee1 100644 --- a/orangecontrib/spectroscopy/utils/spc/spc.py +++ b/orangecontrib/spectroscopy/utils/spc/spc.py @@ -619,7 +619,7 @@ def write_file(self, path, delimiter='\t', newline='\n'): >>> f.writefile('/Users/home/output.txt', delimiter=',') """ - with open(path, 'w') as f: + with open(path, 'wt', encoding="utf8") as f: self.stream_data_txt(f, delimiter, newline) def print_metadata(self): diff --git a/setup.py b/setup.py index 99f5da8c6..167fe9bb8 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ PACKAGE_DATA = {} README_FILE = os.path.join(os.path.dirname(__file__), 'README.pypi') -LONG_DESCRIPTION = open(README_FILE).read() +LONG_DESCRIPTION = open(README_FILE, "rt", encoding="utf8").read() DATA_FILES = [ # Data files that will be installed outside site-packages folder