参考 | PythonBug: UnicodeEncodeError: ‘gbk’ codec can’t encode character
When writing the str character stream into the content of the txt file, this error is reported, most of which are encoding problems, only the first line
needs to be changed:报错代码
with open('./S02E02_cn.txt', 'w') as wf:
wf.write(cn)
wf.close()
open
Inside the brackets, add encoding
the parameter:
with open('./S02E02_cn.txt', 'w', encoding='utf-8') as wf:
wf.write(cn)
wf.close()
can solve the problem