title: Writing massive dictionary to file in python
body: <p>I'm writing a huge dictionary to disk - its handled in memory just fine, but when I output it, I get an error related to the fact that the json written is not complete. How can I write out or stream out a massive dictionary?</p>
  
  <p>I'm using the following:</p>
  
  <pre><code>jsontext = json.dumps(data_dict)
  f = open(pre_data_file, 'w')
  f.write(jsontext)
  f.close()
  </code></pre>
  
  <p>and</p>
  
  <pre><code>f = open(predump_file, 'r')
  jsontxt = f.read()
  f.close()
  sample_dict = dict(json.loads(jsontxt))
  </code></pre>
  
  <p>My file size (incomplete) is: ~300M</p>
  
  <p>Here is the traceback</p>
  
  <pre><code>Traceback (most recent call last):
    File "Combine.py", line 675, in &lt;module&gt;
      sample_range = dict( json.loads(jsontxt))
  ValueError: dictionary update sequence element #0 has length 1; 2 is required
  </code></pre>
  
  <p>when performing a tail on the file (waiting a while as its one line)...</p>