- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在Python 3.5中产生了此错误:
Traceback (most recent call last): File "C:\Users\Owner\AppData\Local\Programs\Python\Python35\lib\shelve.py", line 111, in __getitem__ value = self.cache[key] KeyError: 'P4_vegetables'
Traceback (most recent call last): File "C:\Users\Owner\Documents\Python\Allotment\allotment.py", line 217, in main_program() File "C:\Users\Owner\Documents\Python\Allotment\allotment.py", line 195, in main_program main_program() File "C:\Users\Owner\Documents\Python\Allotment\allotment.py", line 49, in main_program print("Plot 4 - ", s["P4_vegetables"]) File "C:\Users\Owner\AppData\Local\Programs\Python\Python35\lib\shelve.py", line 113, in __getitem__ f = BytesIO(self.dict[key.encode(self.keyencoding)]) File "C:\Users\Owner\AppData\Local\Programs\Python\Python35\lib\dbm\dumb.py", line 141, in __getitem__ pos, siz = self._index[key] # may raise KeyError KeyError: b'P4_vegetables'
最佳答案
已经有一段时间了,但万一有人遇到此情况:以下错误
Traceback (most recent call last):
File "filepath", line 111, in __getitem__
value = self.cache[key]
KeyError: 'item1'
with
块之外的项目,可能会发生。一旦我们开始执行
with
块之外的代码,就关闭了架子。因此,在打开了架子的
with
块之外的架子上执行的任何操作都将被视为无效操作。例如,
import shelve
with shelve.open('ShelfTest') as item:
item['item1'] = 'item 1'
item['item2'] = 'item 2'
item['item3'] = 'item 3'
item['item4'] = 'item 4'
print(item['item1']) # no error, since shelf file is still open
# If we try print after file is closed
# an error will be thrown
# This is quite common
print(item['item1']) #error. It has been closed, so you can't retrieve it.
关于python-3.x - 错误我不明白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37146842/
我是一名优秀的程序员,十分优秀!