title: Using object as key in dictionary in Python - Hash function
body: <p>I am trying to use an object as the key value to a dictionary in Python. I follow the recommendations from some other posts that we need to implement 2 functions: <code>__hash__</code> and <code>__eq__</code></p>
  <p>And with that, I am expecting the following to work but it didn't.</p>
  <pre class="lang-py prettyprint-override"><code>class Test:
      def __init__(self, name):
          self.name = name
          
      def __hash__(self):
          return hash(str(self.name))
          
      def __eq__(self, other):
          return str(self.name) == str(other,name)
          
          
  def TestMethod():
      test_Dict = {}
      
      obj = Test('abc')
      test_Dict[obj] = obj
      
      print &quot;%s&quot; %(test_Dict[hash(str('abc'))].name)       # expecting this to print &quot;abc&quot; 
  </code></pre>
  <p>But it is giving me a key error message:</p>
  <pre class="lang-none prettyprint-override"><code>KeyError: 1453079729188098211
  </code></pre>