diff --git a/spacy/compat.py b/spacy/compat.py index ff73caddd..848ea816a 100644 --- a/spacy/compat.py +++ b/spacy/compat.py @@ -59,6 +59,11 @@ elif is_python3: json_dumps = lambda data: ujson.dumps(data, indent=2) path2str = lambda path: str(path) +def getattr_(obj, name, *default): + if is_python3 and isinstance(name, bytes): + name = name.decode('utf8') + return getattr(obj, name, *default) + def symlink_to(orig, dest): if is_python2 and is_windows: @@ -79,7 +84,7 @@ def is_config(python2=None, python3=None, windows=None, linux=None, osx=None): def normalize_string_keys(old): '''Given a dictionary, make sure keys are unicode strings, not bytes.''' new = {} - for key, value in old: + for key, value in old.items(): if isinstance(key, bytes_): new[key.decode('utf8')] = value else: diff --git a/spacy/util.py b/spacy/util.py index 7120be98c..087a43881 100644 --- a/spacy/util.py +++ b/spacy/util.py @@ -22,7 +22,7 @@ import ujson from .symbols import ORTH from .compat import cupy, CudaStream, path2str, basestring_, input_, unicode_ -from .compat import copy_array, normalize_string_keys +from .compat import copy_array, normalize_string_keys, getattr_ LANGUAGES = {}