Reputation: 41
How would one iterate the contents of a Shelve?
import Shelve
testShelve = Shelve.open("testShelve")
testShelve["key"] = "value"
for k in testShelve.keys():
print(k)
Upvotes: 2
Views: 2084
Reputation: 38
As stated above, the Shelve object is dictionary-like and can be used the same. To print the keys and values of the testShelve object:
for key in testShelve:
print(key, testShelve[key])
Upvotes: 2