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

Allow different encodings for reading JCAMP files #101

Merged
merged 1 commit into from
Jul 22, 2019
Merged
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
8 changes: 6 additions & 2 deletions nmrglue/fileio/bruker.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"""

from __future__ import print_function, division
import locale
import io

__developer_info__ = """
Bruker file format information
Expand Down Expand Up @@ -2091,7 +2093,7 @@ def rm_dig_filter(

# JCAMP-DX functions

def read_jcamp(filename):
def read_jcamp(filename, encoding=locale.getpreferredencoding()):
"""
Read a Bruker JCAMP-DX file into a dictionary.

Expand All @@ -2103,6 +2105,8 @@ def read_jcamp(filename):
----------
filename : str
Filename of Bruker JCAMP-DX file.
encoding : str
Encoding of Bruker JCAMP-DX file. Defaults to the system default locale

Returns
-------
Expand All @@ -2121,7 +2125,7 @@ def read_jcamp(filename):
"""
dic = {"_coreheader": [], "_comments": []} # create empty dictionary

with open(filename, 'r') as f:
with io.open(filename, 'r', encoding=encoding) as f:
while True: # loop until end of file is found

line = f.readline().rstrip() # read a line
Expand Down