Given:
def my_decorator(func):
def wrapper():
print("Something is happening before the function is called.")
#Some code that will execute the decorated method
func()
return wrapper
class parent:
def parentMethod(self):
pass
class child(parent):
@my_decorator
def childMethod(self):
print("Child method called")
if __name__ == '__main__':
childInstance = child()
IS there a way to execute the decorated method without calling the decorated method? If that dosen't make any sense, i want basically every method that is decorated with @my_decorator in child class to be executed when a instance of child class is created.
If both above questions are invalid, is there a way to get the methods that are decorated with "@my_decorator" (the names of the methods) without having to call the decorated methods. As a parallel example, the same way you can get the class name that inherits the parent class with self.__class__.__name__