[Tutor] Shelve: remove dictionary from list
Timo
timomlists at gmail.com
Tue Mar 3 18:18:24 CET 2009
Hello all, I'm using the Shelve module to store dictionaries in a list
as a value of a key.
So:
key = [{'keyA' : 1, 'keyB' : 2}, {'key1' : 1, 'key2' : 2}]
The problem is I can't remove a dictionary from the list.
import shelve
s = shelve.open('file')
try:
for index, value in enumerate(s['key']):
if value['keyA'] == 1 and value['keyB'] == 2:
del value[index]
finally:
s.close()
If I do some printing in between, I can see the dictionary actually gets
removed, but doesn't get saved. Any ideas why?
More information about the Tutor
mailing list