title: How do I save a file object to a shelve file?
body: <p>When I run the following code:</p>
  
  <pre><code>import shelve
  
  input = open("input.txt",)
  shelveFile = shelve.open("myData")
  shelveFile["inputFile"] = input
  input.close()
  shelveFile.close()
  </code></pre>
  
  <p>I expect the shelve file <code>myData</code> to hold the file object <code>input</code>. Instead, running the code produces the following error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/Users/ashutoshmishra/Documents/Sandbox/Sandbox3.py", line 5, in &lt;module&gt;
      shelveFile["inputFile"] = input
    File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/shelve.py", line 124, in __setitem__
      p.dump(value)
  TypeError: cannot serialize '_io.TextIOWrapper' object
  </code></pre>
  
  <p>I was wondering why I could not save the file object <code>input</code> to the shelve file <code>myData</code>?</p>