I will let the following terminal session speak for itself:
>>> import shelve
>>> s = shelve.open('TestShelve')
>>> from collections import deque
>>> s['store'] = deque()
>>> d = s['store']
>>> print s['store']
deque([])
>>> print d
deque([])
>>> s['store'].appendleft('Teststr')
>>> d.appendleft('Teststr')
>>> print s['store']
deque([])
>>> print d
deque(['Teststr'])
Shouldn’t d and s['store'] point to the same object? Why does appendleft work on d but not on s['store']?
It turns out they’re not the same so any operations you perform on them won’t match:
To modify items as you coded, you need to pass the parameter
writeback=True:See the documentation:
You can also do it with
writeback=Falsebut then you need to write the code exactly as in the provided example: