title: Setting an Item in nested dictionary with __setitem__
body: <p>Here's what I did, trying to create a wrapper for a dict-like database, among other functions:  </p>
  
  <pre><code>    class database(object):
          def __init__(self, name):
              self.name = name
              self.db = anydbm.open(name, 'c')
  
          def __getitem__(self, key):
              key = str(key)
              try:
                  self.db = anydbm.open(self.name, 'w') 
              except Exception,e: 
                  raise e
              else:
                  return cPickle.loads(self.db[key])
              finally:  
                  self.db.close()
  
          def __setitem__(self, key, value):
              key = str(key)
              value = cPickle.dumps(value)
              try:
                  self.db = anydbm.open(self.name, 'w')
              except Exception,e:
                  print e 
              else:
                  self.db[key] = value
              finally:  
                  self.db.close()
  </code></pre>
  
  <p>When I try to define a new key in a dict nested within, it seems getitem is returning a value instead of a reference, so the definition is not finally modified after the setitem. </p>
  
  <pre><code>&gt;&gt;&gt; from database import database
  &gt;&gt;&gt; db = database('test')
  &gt;&gt;&gt; db['a'] = {'alpha':'aaa'}
  &gt;&gt;&gt; db['a']['alpha'] = 'bbb'
  &gt;&gt;&gt; print db
  {'a': {'alpha': 'aaa'}} //The value is not modified
  </code></pre>