python读txt文件报错UnicodeDecodeError: ‘gbk‘ codec can‘t decode
生活随笔
收集整理的這篇文章主要介紹了
python读txt文件报错UnicodeDecodeError: ‘gbk‘ codec can‘t decode
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
python讀取文件時提示"UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0x80 in position 205: illegal multibyte sequence"
原代碼:
file = open(r"D:\PythonSourceCode\ReadFile\abc.txt", "r") data = file.read() print(data) file.close()修改為:
file = open(r"D:\PythonSourceCode\ReadFile\abc.txt", "r", encoding='UTF-8') data = file.read() print(data) file.close()總結
以上是生活随笔為你收集整理的python读txt文件报错UnicodeDecodeError: ‘gbk‘ codec can‘t decode的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ELK开机自启动脚本
- 下一篇: Ubuntu18 Win10搭建Caff