From c41ee7397d00cf137ce935e1a789d8768573b3a7 Mon Sep 17 00:00:00 2001 From: inuyasha2012 Date: Wed, 8 Nov 2017 09:37:48 +0800 Subject: [PATCH] fix python3 open stopwords file UnicodeDecodeError bug --- synonyms/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/synonyms/__init__.py b/synonyms/__init__.py index 71bee68..782b897 100755 --- a/synonyms/__init__.py +++ b/synonyms/__init__.py @@ -104,7 +104,10 @@ def _load_stopwords(file_path): load stop words ''' global _stopwords - words = open(file_path, 'r') + if sys.version_info[0] < 3: + words = open(file_path, 'r') + else: + words = open(file_path, 'r', encoding='utf-8') stopwords = words.readlines() for w in stopwords: _stopwords.add(any2unicode(w).strip())