蔡晨曦 发表于 2021-7-4 17:49:07

打开文本问题

我想打开一个文本,弹出以下错误,怎么解决呢
>>> e=open('E:\\新建文本文档.txt')
>>> e
<_io.TextIOWrapper name='E:\\新建文本文档.txt' mode='r' encoding='cp936'>
>>> e.read()

Traceback (most recent call last):
File "<pyshell#35>", line 1, in <module>
    e.read()
UnicodeDecodeError: 'gbk' codec can't decode byte 0xa2 in position 17: illegal multibyte sequence

qiuyouzhi 发表于 2021-7-4 17:50:50

改成这样:
e=open('E:\\新建文本文档.txt', encoding = "utf-8")

不能懒 发表于 2021-7-4 20:50:18

解码问题
页: [1]
查看完整版本: 打开文本问题