has_key搁置方法的不稳定行为

时间:2015-09-29 22:33:56

标签: python shelve

我一直在使用python的搁置库(不在多处理环境中),并且在使用has_key()方法时我一直在观察不稳定的行为。当我知道密钥存在于货架中时,它有时会返回True,有时会返回False。这种行为的常见原因是什么?

import shelve

some_key = 'not relevant'
s = shelve.open('cache.db')
if s.has_key(some_key):
   var = s[some_key]
   print 'found key', some_key

s.close()

注意:VM VirtualBox中的Python 2.7,Ubuntu 14.04,运行在i7 x86-64bit

0 个答案:

没有答案
相关问题