python搁架键

2024-10-16 17:22:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我用shelve模块提取了一些字典。有一次,我决定用Notepad++打开数据被pickle的文件。有西里尔字母,所以我试着用不同的编码器解码(但没有成功)。 之后,我开始在运行python脚本时出错:

    Traceback (most recent call last):
  File "C:\Users\Baysarov\AppData\Local\Programs\Python\Python35-32\lib\shelve.py", line 111, in __getitem__
    value = self.cache[key]
KeyError: 'chrs'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<pyshell#5>", line 1, in <module>
    print(db['chrs']['Arma 2'])
  File "C:\Users\Baysarov\AppData\Local\Programs\Python\Python35-32\lib\shelve.py", line 113, in __getitem__
    f = BytesIO(self.dict[key.encode(self.keyencoding)])
  File "C:\Users\Baysarov\AppData\Local\Programs\Python\Python35-32\lib\dbm\dumb.py", line 141, in __getitem__
    pos, siz = self._index[key]     # may raise KeyError
KeyError: b'chrs'

文件中的其他词典也是如此。 如果我打印以下内容,可以看到钥匙的存在:

^{pr2}$

能修好吗?在


Tags: keyinpyselfliblocallineusers