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 on 2018-01-03 17:18  一只猪儿虫  阅读(14513)  评论(0编辑  收藏  举报