Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Explicitely define utf8 encoding on open() for text files #708

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading