classification
Title: Shelve second tier array subscript "[ ]" key creation doesn't work
Type: behavior Stage: resolved
Components: None Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: cpiekarski, ned.deily
Priority: normal Keywords:

Created on 2011-11-01 22:54 by cpiekarski, last changed 2011-11-01 23:23 by ned.deily. This issue is now closed.

Messages (2)
msg146816 - (view) Author: Chris Piekarski (cpiekarski) Date: 2011-11-01 22:54
Shelve object second tier array subscript key generation doesn't behave the same way dictionary object do.

>>> import shelve
>>> x = shelve.open("tst1.shelve")
>>> x["one"] = {}
>>> x
{'one': {}}
>>> x["one"]["two"] = 2
>>> x
{'one': {}}

Whereas with a dictionary it works:

>>> y = {}
>>> y["one"] = {}
>>> y["one"]["two"] = 2
>>> y
{'one': {'two': 2}}
msg146817 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2011-11-01 23:23
shelve is behaving as documented.  Because the shelve dictionary entry is mutable (a dictionary), you need to set writeback=True to get the behavior you expect.  http://docs.python.org/library/shelve.html
History
Date User Action Args
2011-11-01 23:23:59ned.deilysetstatus: open -> closed

nosy: + ned.deily
messages: + msg146817

resolution: not a bug
stage: resolved
2011-11-01 22:54:06cpiekarskicreate