python读取中文文本出错,'gbk' codec can't decode byte 0xad in position 5: illegal multibyte sequence

在这里插入图片描述在open()括号里添加第三个参数encoding="utf-8"就好了。
file = open(“D:\Programming_exercise\python\Unit6_CalHamletV1\File.txt”,“rt”,encoding=“utf-8”)
正确读取结果:
在这里插入图片描述
注意,文本文件中有中文标点符号也要加这个参数

发布了3 篇原创文章 · 获赞 0 · 访问量 94

猜你喜欢

转载自blog.csdn.net/weixin_40162095/article/details/104234554