Discuss / Python / 打开txt文件出错

打开txt文件出错

Topic source

txt 文件里写了“你好,再见”,想用python读出来结果报错,请问怎么修改?

file=open('abc.txt','r',encoding='utf-8')
file.read()

(result, consumed) = self._buffer_decode(data, self.errors, final) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb2 in position 0: invalid start byte

f = open('e:a.txt', 'r', encoding = 'gbk')

houbo111

#3 Created at ... [Delete] [Delete and Lock User]

代码前面加上

# -*- coding:utf-8 -*-

  • 1

Reply