python搁置键错误

时间:2016-08-11 06:50:47

标签: python shelve

我使用搁置模块腌制了一些词典。有一次,我决定用Notepad ++打开用于腌制数据的文件。有西里尔字母,所以我试着用不同的编码器解码它们(虽然没有成功)。 之后,我在运行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'

与文件中的每个其他字典相同。 如果我打印,可以看到键存在:

>>> print(list(db.keys()))
['yb_imgs', 'chrs', 'gnames', 'plati_ids', 'tags', 'descrs']

可以修复吗?

0 个答案:

没有答案