title: Writing a dictionary to a text file?
body: <p>I have a dictionary and am trying to write it to a file.</p>
  
  <pre><code>exDict = {1:1, 2:2, 3:3}
  with open('file.txt', 'r') as file:
      file.write(exDict)
  </code></pre>
  
  <p>I then have the error</p>
  
  <pre class="lang-none prettyprint-override"><code>file.write(exDict)
  TypeError: must be str, not dict
  </code></pre>
  
  <p>So I fixed that error but another error came</p>
  
  <pre><code>exDict = {111:111, 222:222}
  with open('file.txt', 'r') as file:
      file.write(str(exDict))
  </code></pre>
  
  <p>The error:</p>
  
  <pre class="lang-none prettyprint-override"><code>file.write(str(exDict))
  io.UnsupportedOperation: not writable
  </code></pre>
  
  <p>I have no idea what to do as I am still a beginner at python.
  If anyone knows how to resolve the issue, please provide an answer.</p>
  
  <p>NOTE: I am using python 3, not python 2</p>