UnicodeDecodeError: 'gbk' codec can't decode byte 0x82 in position 66: illegal multibyte sequence

代码如下:

file_in="C:\\Users\\Administrator\\Desktop\\parking datum.txt"
data=''
fbegin=0
fend=0
d=''
with open(file_in,"r") as file:
    for i in file.readlines():
        for e in i:
            if e=='"':
                continue;
            if e=='}':
                fbegin=0
                data=(data+d)
                d=''
            if fbegin==1:``
                d=d+e;  
            if e=='{':
                fbegin=1
print('----------------')
print(data)

上述代码是为了把一个文件读入为字符串并在读的过程中进行了一定的处理,但是python3.6显示:
UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0x82 in position 66: illegal multibyte sequence
经过上网查询,发现txt文本分为4中编码方式:ANSI、Unicode、Unicode big endian和UTF-8。打开txt点击文件-另存为会显示当前txt的编码方式(会将当前的编码方式当成另存为的默认格式)。而该报错是指gbk编码译码器

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值