Dynamically removing methods in new-style classes
hniksic at xemacs.org
Wed Sep 12 16:41:08 CEST 2007
agupta0318 at gmail.com writes:
> I am trying unsuccessfully to remove some methods from an instance,
You can't remove the method from an instance because the method is
stored in its class.
> With the older python classes I could have done:
> self.__class__.__dict__[''test1"] to achieve the desired result.
self.__class__.test1 still works, doesn't it? Removing methods can be
achieved the same way:
>>> class X(object):
... def blah(self): pass
<bound method X.blah of <__main__.X object at 0xb7d46bcc>>
>>> del type(x).blah
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'X' object has no attribute 'blah'
More information about the Python-list