提交 640065b0 编写于 作者: Z zhangxuefei

fix bug that read file encoding in python2

上级 2ece967d
......@@ -72,13 +72,21 @@ class TextFileParser(object):
pass
def parse(self, txt_file, use_strip=True):
with codecs.open(txt_file, "r", sys_stdin_encoding()) as file:
contents = []
for line in file:
if use_strip:
line = line.strip()
if line:
contents.append(line)
contents = []
try:
with codecs.open(txt_file, "r", encoding="utf8") as file:
for line in file:
if use_strip:
line = line.strip()
if line:
contents.append(line)
except:
with codecs.open(txt_file, "r", encoding="gbk") as file:
for line in file:
if use_strip:
line = line.strip()
if line:
contents.append(line)
return contents
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册