title: Error Pickling in Python: io.UnsupportedOperation: read
body: <p>I am trying to learn how to <code>pickle</code> and save an object in python. However, when I use the <a href="http://www.astrobetter.com/python-tip-storing-data/" rel="noreferrer">sample code</a> below I get the following error: <code>io.UnsupportedOperation: read</code> which traces back to <code>favorite_color = pickle.load(f_myfile)</code>. I cannot find a good explanation of this particular error. What am I doing wrong and how do I correct it?</p>
  
  <pre><code>import pickle  # or import cPickle as pickle
  
  # Create dictionary, list, etc.
  favorite_color = { "lion": "yellow", "kitty": "red" }
  
  # Write to file
  f_myfile = open('myfile.pickle', 'wb')
  pickle.dump(favorite_color, f_myfile)
  f_myfile.close()
  
  # Read from file
  f_myfile = open('myfile.pickle', 'wb')
  favorite_color = pickle.load(f_myfile)  # variables come out in the order you put them in
  f_myfile.close()
  </code></pre>