Skip to content

Commit

Permalink
Merge pull request #708 from markotoplak/define-encodings
Browse files Browse the repository at this point in the history
[FIX] Explicitely define utf8 encoding on open() for text files
  • Loading branch information
markotoplak authored Feb 6, 2024
2 parents c51ecb0 + 7d23136 commit 480feea
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion orangecontrib/spectroscopy/io/maxiv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions orangecontrib/spectroscopy/io/neaspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion orangecontrib/spectroscopy/io/soleil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('#'):
Expand Down
2 changes: 1 addition & 1 deletion orangecontrib/spectroscopy/utils/spc/spc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 480feea

Please sign in to comment.