title: Store a dictionary in a file for later retrieval
body: <p>I've had a search around but can't find anything regarding this...</p>
  
  <p>I'm looking for a way to save a dictionary to file and then later be able to load it back into a variable at a later date by reading the file.</p>
  
  <p>The contents of the file don't have to be "human readable" it can be as messy as it wants.</p>
  
  <p>Thanks
   - Hyflex</p>
  
  <h1>EDIT</h1>
  
  <pre><code>import cPickle as pickle
  
  BDICT = {}
  
  ## Automatically generated START
  name = "BOB"
  name_title = name.title()
  count = 5
  BDICT[name_title] = count
  
  name = "TOM"
  name_title = name.title()
  count = 5
  BDICT[name_title] = count
  
  name = "TIMMY JOE"
  name_title = name.title()
  count = 5
  BDICT[name_title] = count
  ## Automatically generated END
  
  if BDICT:
      with open('DICT_ITEMS.txt', 'wb') as dict_items_save:
          pickle.dump(BDICT, dict_items_save)
  
  BDICT = {} ## Wiping the dictionary
  
  ## Usually in a loop
  firstrunDICT = True
  
  if firstrunDICT:
      with open('DICT_ITEMS.txt', 'rb') as dict_items_open:
          dict_items_read = dict_items_open.read()
          if dict_items_read:
              BDICT = pickle.load(dict_items_open)
              firstrunDICT = False
              print BDICT
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\test3.py", line 35, in &lt;module&gt;
      BDICT = pickle.load(dict_items_open)
  EOFError
  </code></pre>