title: Updating A Shelved Dictionary written on a file
body: <p>I have a shelved dictionary 'word_dictionary' in a file and I can access it in the main program. I need to make a user able to add an entry to the dictionary. But I'm unable to save the entry in the shelved dictionary and I get the error: </p>
  
  <pre><code>Traceback (most recent call last):
    File "/Users/Jess/Documents/Python/Coursework/Coursework.py", line 16, in &lt;module&gt;
      word_dictionary= dict(shelf['word_dictionary'])
  TypeError: 'NoneType' object is not iterable
  </code></pre>
  
  <p>When the code loops back around - the code works on the first run.</p>
  
  <p>This is the code which is meant to update the dictionary:</p>
  
  <pre><code>    shelf = shelve.open("word_list.dat")
      shelf[(new_txt_file)] = new_text_list
      shelf['word_dictionary'] = (shelf['word_dictionary']).update({(new_dictionary_name):(new_dictionary_name)})
      #not updating
      shelf.sync()
      shelf.close()
  </code></pre>
  
  <p>And this is the code which doesn't work after the update doesn't complete (I don't think this is part of the problem but I may be wrong)</p>
  
  <pre><code>shelf = shelve.open("word_list.dat")
  shelf.sync()
  word_dictionary= dict(shelf['word_dictionary'])
  </code></pre>
  
  <p>Thank you in advance for your help and patience!
  <strong>UPDATE</strong>
  This is the start of the code where I call word_dictionary which is imported:</p>
  
  <pre><code>while True:
   shelf = shelve.open("word_list.dat")
   print('{}'.format(shelf['word_dictionary']))
   word_dictionary= dict(shelf['word_dictionary'])
   print(word_dictionary)
   word_keys = list(word_dictionary.keys())
   shelf.close()
  </code></pre>
  
  <p>This is how the original dictionary I want to add to sits:</p>
  
  <pre><code>shelf['word_dictionary'] = {'Hope Words': 'hope_words', 'Merry Words': 'merry_words', 'Amazement Words': 'amazement_words'}
  </code></pre>