未验证 提交 0fd67bac 编写于 作者: M mapingshuo 提交者: GitHub

Merge pull request #1532 from PaddlePaddle/mapingshuo-patch-1

modify open file code for python3
......@@ -21,6 +21,11 @@ import numpy as np
import time, datetime
import os, sys
def maybe_open(filepath):
if sys.version_info <= (3, 0): # for python2
return open(filepath, 'r')
else:
return open(filepath, 'r', encoding="utf-8")
def Glove840B_300D(filepath, keys=None):
"""
......@@ -33,7 +38,7 @@ def Glove840B_300D(filepath, keys=None):
print("please wait for a minute.")
start = time.time()
word2vec = {}
with open(filepath, "r") as f:
with maybe_open(filepath) as f:
for line in f:
if sys.version_info <= (3, 0): # for python2
line = line.decode('utf-8')
......
......@@ -68,8 +68,10 @@ def maybe_open(file_name):
" |- readme.txt\n"
" |- wordvec.txt\n")
raise RuntimeError(msg)
if sys.version_info <= (3, 0): # for python2
return open(file_name, 'r')
else:
return open(file_name, 'r', encoding="utf-8")
def tokenized_question_pairs(file_name):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册