jneidel
jneidel

Reputation: 41

Iterate/Loop over Shelve

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

Answers (1)

Liz Hesser
Liz Hesser

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

Related Questions