问题描述:
python在使用open打开.trc文件的时候报错,如下图:
fd = open("mbb_file/A.txt", "r")
try:
text = fd.readline() #结果为str类型
print (type(text))
print ("text=",text)
finally:
fd.close()
UnicodeDecodeError: 'gbk' codec can't decode byte 0xd5 in position 5382: illegal multibyte sequence
问题原因:
读取编码错误
解决方案:
fd = open("file/A.trc", "r", errors='ignore')
try:
text = fd.readline() #结果为str类型
print (type(text))
print ("text=",text)
finally:
fd.close()
<class 'str'>
text= [12:07:26.970] [18555] [60733] [ ] [ ] [ ] /I : qxwz_get_thread_name name:qx_k_tneventthr