Tsusan 发表于 2022-7-14 16:58:07

求助求助

用python打开文件的时候显示
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
    w.read()
UnicodeDecodeError: 'gbk' codec can't decode byte 0xad in position 22: illegal multibyte sequence
怎么解决,还有这是为什么呢


青出于蓝 发表于 2022-7-14 17:02:46

编码问题,open函数中加个参数 encoding='utf-8’

python爱好者. 发表于 2022-7-14 18:05:36

w = open("文件名",encoding = "utf8")
w.read()

Victor0321 发表于 2022-7-15 00:20:30

with open(filename , 'rb',encoding = 'utf-8')

Tsusan 发表于 2022-7-16 15:46:31

青出于蓝 发表于 2022-7-14 17:02
编码问题,open函数中加个参数 encoding='utf-8’

它原因是什么啊,就是什么编码问题
页: [1]
查看完整版本: 求助求助