Skip to content

Instantly share code, notes, and snippets.

@durden
Created March 7, 2014 23:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save durden/9421967 to your computer and use it in GitHub Desktop.
Save durden/9421967 to your computer and use it in GitHub Desktop.
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