How to make every Class Method call a specified method before execution?
- by norm
I want to make my Python Class behave in such a way that when any Class method is called a default method is executed first without explicitly specifying this in the called Class. An example may help :)
Class animals:
def _internalMethod():
self.respires = True
def cat():
self._internalMethod()
self.name = 'cat'
def dog():
self._internalMethod()
self.name = 'dog'
I want _internalMethod() to be called automatically when any method is called from an instance of animals, rather than stating it explicitly in the def of each method. Is there an elegant way to do this?
Cheers,