I have already figured out the answer to that, so I am placing it here as a question to myself - for the sake of those that may come up with similar question.
Basically, I wanted to be able to delete an object method. The reason?
I have an action that has to be executed once per object life. This action cannot be placed in the __init__ method since I need system fully initialized before it is performed.
I have a suitable place holder for that action - a method existing in the parent class. But I would like to be able to avoid checking the condition every time the method is called by framework.
So I tried this approach:
In [193]: class Parent(object): def place_for_action(self): print 'This is parent' .....: In [194]: class Child(Parent): def place_for_action(self): super(Child, self).place_for_action() print 'This is child' delattr(self, 'place_for_action') .....: When I tried it, I failed
In [186]: c= Child() In [187]: c.place_for_action() This is child --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) /homes/markg/<ipython-input-187-da53ac96ffa9> in <module>() ----> 1 c.place_for_action() /homes/markg/<ipython-input-185-7037db53bd87> in do_once(self) 2 def place_for_action(self): 3 print 'This is child' ----> 4 delattr(self, 'place_for_action') 5 AttributeError: 'Child' object attribute 'place_for_action' is read-only
__init__? What other instantiation is required?