title: Python pickle/unpickle a list to/from a file
body: <p>I have a list that looks like this:</p>
  
  <pre><code>a = [['a string', [0, 0, 0], [22, 'bee sting']], ['see string', 
      [0, 2, 0], [22, 'd string']]]
  </code></pre>
  
  <p>and am having problems saving it and retrieving it.</p>
  
  <p>I can save it ok using pickle:</p>
  
  <pre><code>with open('afile','w') as f:
      pickle.dump(a,f)
  </code></pre>
  
  <p>but get the following error when I try to load it:</p>
  
  <pre><code>pickle.load('afile')
  
  Traceback (most recent call last):
    File "&lt;pyshell#116&gt;", line 1, in &lt;module&gt;
      pickle.load('afile')
    File "C:\Python27\lib\pickle.py", line 1378, in load
      return Unpickler(file).load()
    File "C:\Python27\lib\pickle.py", line 841, in __init__
      self.readline = file.readline
  AttributeError: 'str' object has no attribute 'readline'
  </code></pre>
  
  <p>I had thought that I could convert to a numpy array and use <code>save</code>, <code>savez</code> or <code>savetxt</code>. However I get the following error:</p>
  
  <pre><code>&gt;&gt;&gt; np.array([a])
  
  Traceback (most recent call last):
    File "&lt;pyshell#122&gt;", line 1, in &lt;module&gt;
      np.array([a])
  ValueError: cannot set an array element with a sequence
  </code></pre>