Problem with shelve / nested lists
Michael Schmitt
ms at NOMAIL.de
Sat Jul 13 19:53:10 EDT 2002
Hello.
I'm trying to use a shelve as a disc based dictionary, but have problems
with nested lists. If I store a nested list as value, inner lists seem to
be immutable.
According to the library reference, shelves can store "essentially
arbitrary Python objects" and "recursive data types".
What is my misunderstanding?
Python2.2:
>>> import shelve
>>> d1= shelve.open('dict.dat','c')
>>> d1['bla']= [1,2,[10,20]]
>>> d1['bla'][2]
[10, 20]
>>> d1['bla'][2].append(30)
>>> d1['bla'][2]
[10, 20]
Using a dictionary instead of the shelve, lets append to the inner list.
>>> d2= {}
>>> d2['bla']= [1,2,[10,20]]
>>> d2['bla'][2]
[10, 20]
>>> d2['bla'][2].append(30)
>>> d2['bla'][2]
[10, 20, 30]
Thanks for any hint,
Michael
More information about the Python-list
mailing list