写入文件中遇到 UnicodeEncodeError: ‘gbk’ codec can’t encode character 错误的解决办法

sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf-8') #改变标准输出的默认编码
#或
f = open('out.txt','a+',encoding='utf-8')    #打开文件时声明编码方式

str转bytes为encode,bytes转str为decode

常用中文编码名称