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)
原因:文件編碼不一致導致
解決方案: 加上編碼限制

 




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM