Marko Rauhamaa <>:

> Christian Heimes <>:
>> Python creates a new bound method object every time. A bound method
>> object is a callable object that keeps a strong reference to the
>> function, class and object. The bound method object adds the object as
>> first argument to the function (aka 'self').
> I stand corrected. I had thought the trampoline ("bound method
> object") was created once and for all.

Sure enough. The principle is explicitly specified in <URL:>.


   >>> class X:
   ...   def f(self):
   ...     print("Hello")
   >>> x = X()
   >>> x.f()
   >>> def f(): print("Meh")
   >>> x.f = f
   >>> x.f()
   >>> delattr(x, "f")
   >>> x.f()

IOW, you can override a method with setattr() but you cannot delete a
method with delattr().


Reply via email to