title: Python Overwrite Dictionary to Text File doesn't work... why?
body: <p><Br>
  I've been previously writing code for a quiz program with a text file that stores all of the participants' results. The code that converts the text file to a dictionary and the text file itself are shown below:</p>
  
  <p>Code:</p>
  
  <pre><code>import collections
  from collections import defaultdict
  scores_guessed = collections.defaultdict(lambda: collections.deque(maxlen=4))
  with open('GuessScores.txt') as f:
      for line in f:
          name,val = line.split(":")
          scores_guessed[name].appendleft(int(val))
  
  for k in sorted(scores_guessed):
      print("\n"+k," ".join(map(str,scores_guessed[k])))
  
  writer = open('GuessScores.txt', 'wb')
  
  for key, value in scores_guessed.items():       
      output = "%s:%s\n" % (key,value)
      writer.write(output)
  </code></pre>
  
  <p>The text file appears like this:</p>
  
  <pre><code>Jack:10
  Dave:20
  Adam:30
  Jack:40
  Adam:50
  Dave:60
  Jack:70
  Dave:80
  Jack:90
  Jack:100
  Dave:110
  Dave:120
  Adam:130
  Adam:140
  Adam:150
  </code></pre>
  
  <p>Now, when I run the program code, the dictionary appears like this:</p>
  
  <pre><code>Adam 150 140 130 50
  
  Dave 120 110 80 60
  
  Jack 100 90 70 40
  </code></pre>
  
  <p>Now, this arranges the dictionary into order of highest scores, and the top 4 scores!</p>
  
  <p>I want the python IDLE to overwrite the GuessScores.txt to this:</p>
  
  <pre><code>Adam:150
  Adam:140
  Adam:130
  Adam:50
  Dave:120
  Dave:110
  Dave:80
  Dave:60
  Jack:100
  Jack:90
  Jack:70
  Jack:40
  </code></pre>
  
  <p>BUT when I run the code, this error appears:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/Users/Ahmad/Desktop/Test Files SO copy/readFile_prompt.py", line 16, in &lt;module&gt;
      writer.write(output)
  TypeError: 'str' does not support the buffer interface
  </code></pre>
  
  <p>The GuessScores.txt file is empty because it cannot write to the file, since there is the error above. </p>
  
  <p>Why is this happening? And what is the fix? I have asked this previously but there were numerous issues. I am running Python 3.3.2 on a Mac 10.8 Mavericks iMac, if that makes any help. </p>
  
  <p>Thanks, 
  Delbert.</p>