title: How to overwrite __repr__ method for an already-instantiated class python
body: <p>I'm working with a 3rd-party library which has a poor <strong>repr</strong> for a class and I would like to overwrite it once an instance of that class has been created.</p>
  
  <p>I saw how to create bound methods in an existing object. </p>
  
  <pre><code>class toy():
      pass
  
  inst= toy()
  
  class inhtoy():
      def __new__(cls,obj):
          def __repr__(self):
              return 'Sucessful'
          import types
          obj.__repr__ = types.MethodType(__repr__,obj)
          return obj
  
  t = inhtoy(inst)
  </code></pre>
  
  <p>Indeed, if I call t.<strong>repr</strong>() it works, however it does not overwrite the original <strong>repr</strong>. It appears as <code>&lt;bound method inhtoy.__new__.&lt;locals&gt;.__repr__ of &lt;__main__.toy object at 0x7f76e0b61f98&gt;&gt;</code>
  a kind of local method.<br>
  Calling <code>repr(t)</code> still points to the original representation <code>'&lt;__main__.toy object at 0x7f76e0b61f98&gt;'</code> but not the overwritten one.</p>
  
  <p>Is there a way to properly do this?<br>
  Thanks </p>