fool.load_userdict(path)出现编码文件出错,UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position

错误问题:UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 34: illegal multibyte sequence

解决方法:    

      解决办法1

             FILE_OBJECT= open('order.log','r', encoding='UTF-8')

      解决办法2.

             FILE_OBJECT= open('order.log','rb')

          以上都无法解决!

GitHub上的源码:with open(path,'r',encoding='UTF-8') as f:

    def add_dict(self, path):
        words = []

        with open(path,'r',encoding='UTF-8') as f:
            for i, line in enumerate(f):
                line = line.strip("\n").strip()
                if not line:
                    continue
                line = line.split()
                word = line[0].strip()
                self.trie.add_keyword(word)
                if len(line) == 1:
                    weight = 1.0
                else:
                    weight = float(line[1])
                weight = float(weight)
                self.weights[word] = weight
                words.append(word)
        self.sizes += len(self.weights)

python上安装的包里代码为: with open(path) as f:

    def add_dict(self, path):
        words = []

        with open(path) as f:
            for i, line in enumerate(f):
                line = line.strip("\n").strip()
                if not line:
                    continue
                line = line.split()
                word = line[0].strip()
                self.trie.add_keyword(word)
                if len(line) == 1:
                    weight = 1.0
                else:
                    weight = float(line[1])
                weight = float(weight)
                self.weights[word] = weight
                words.append(word)
        self.sizes += len(self.weights)

最终解决办法:将包内代码改为GitHub上的代码问题完美解决!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值