シェルフモジュールを使用すると、私には驚くべき動作がいくつかあります。 keys()、iter()、およびiteritems()は、棚のすべてのエントリを返しません!ここでは、コードです:シェルフモジュールに問題がありますか?
cache = shelve.open('my.cache')
# ...
cache[url] = (datetime.datetime.today(), value)
以降:
cache = shelve.open('my.cache')
urls = ['accounts_with_transactions.xml', 'targets.xml', 'profile.xml']
try:
print list(cache.keys()) # doesn't return all the keys!
print [url for url in urls if cache.has_key(url)]
print list(cache.keys())
finally:
cache.close()
、ここでは出力です:
['targets.xml']
['accounts_with_transactions.xml', 'targets.xml']
['targets.xml', 'accounts_with_transactions.xml']
は、誰もがこの前に実行され、そしてこの問題を回避するには、すべての可能なキャッシュキーを知らなくても、そこにあります先行技術0002
どのdbmモジュールを使用していますか?私のバグのように聞こえる。 –
whichdb.whichdb( 'my.cache')=> dbm –
(btw、これはMacの場合はPython 2.5です) –