Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Deleting class methods in Python..a bad idea
>>> class Foo(object):
... def a(self): return 'a'
...
>>> x = Foo()
>>> print x.a()
a
>>>
>>> def b(self):
... return 'b'
...
>>> Foo.b = b
>>>
>>> print x.b()
b
>>>
>>> print x.a()
a
>>>
>>> del Foo.__dict__['a']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'dictproxy' object does not support item deletion
>>> delattr(Foo, 'b')
>>>
>>> print x.b()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'Foo' object has no attribute 'b'
>>> print x.a()
a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.