title: Writing a dict to txt file and reading it back?
body: <p>I am trying to write a dictionary to a txt file. Then read the dict values by typing the keys with <code>raw_input</code>. I feel like I am just missing one step but I have been looking for a while now.</p>
  
  <p>I get this error</p>
  
  <pre class="lang-none prettyprint-override"><code>File "name.py", line 24, in reading
      print whip[name]
  TypeError: string indices must be integers, not str
  </code></pre>
  
  <p>My code:</p>
  
  <pre><code>#!/usr/bin/env python
  from sys import exit
  
  class Person(object):
      def __init__(self):
          self.name = ""
          self.address = ""
          self.phone = ""
          self.age = ""
          self.whip = {}
  
      def writing(self):
          self.whip[p.name] = p.age, p.address, p.phone
          target = open('deed.txt', 'a')
          target.write(str(self.whip))
          print self.whip
  
      def reading(self):
          self.whip = open('deed.txt', 'r').read()
          name = raw_input("&gt; ")
          if name in self.whip:
              print self.whip[name]
  
  p = Person()
  
  while True:
      print "Type:\n\t*read to read data base\n\t*write to write to data base\n\t*exit to exit"
      action = raw_input("\n&gt; ")
      if "write" in action:
          p.name = raw_input("Name?\n&gt; ")
          p.phone = raw_input("Phone Number?\n&gt; ")
          p.age = raw_input("Age?\n&gt; ")
          p.address = raw_input("Address?\n&gt;")
          p.writing()
      elif "read" in action:
          p.reading()
      elif "exit" in action:
          exit(0)
  </code></pre>