python 把一文件包含中文的字符写到另外文件乱码 UnicodeDecodeError: 'gbk' codec can't decode byte 0xac in position

报错的代码是:

file2 = open('target.txt','w')
for line in open('test.txt'):
file2.write(line)
原因:文件编码不一致导致
解决方案: 加上编码限制

posted @ 2020-08-18 19:12  sunyllove  阅读(146)  评论(0编辑  收藏  举报