文件内容读取编码错误时
编码方式可以根据自己的需要调整
decode_list=["ISO-8859-1","utf-8",'gb18030', 'ISO-8859-2','gb2312',"gbk" ]#编码集
for k in decode_list:#编码集循环
try:
with open ('filename','r', encoding=k,errors='ignore') as new_file:
.......
break
except:
print("can't decode in " + k)
用os.popen.read()获取命令返回内容编码错误时
res = os.popen(command)
diff = res.buffer.read().decode(encoding='ISO-8859-1')