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

fix bug that read file encoding in python2

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