title: Usage of pickle.dump in Python
body: <p>I'm trying to learn how to use the <code>pickle</code> module in Python:</p>
  
  <pre><code>import pickle
  x = 123
  f = open('data.txt','w')
  pickle.dump(x,f)
  </code></pre>
  
  <p>Here's what I get:</p>
  
  <pre><code>Traceback (most recent call last):
    File "D:\python\test.py", line 5, in &lt;module&gt;
      pickle.dump(x,f)
  TypeError: must be str, not bytes
  </code></pre>
  
  <p>However, this code works just fine:</p>
  
  <pre><code>import pickle
  dump = pickle.dump(123)
  print(dump)
  </code></pre>
  
  <p><br>
  What am I doing wrong?</p>