参考 | PythonBug: UnicodeEncodeError: ‘gbk‘ codec can‘t encode character

参考 | 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()

openInside the brackets, add encodingthe parameter:

with open('./S02E02_cn.txt', 'w', encoding='utf-8') as wf:
	wf.write(cn)
wf.close()

can solve the problem

Guess you like

Origin blog.csdn.net/JackyAce6880/article/details/125701919