I need to:
- Receive a method as argument (directly from the class, without instance)
- Create an instance
- Execute said method from instance
The thing is, how can I reliably get the class out of the method? I've tried researching something in the inspect
module, but because there is no instance, it thinks of the method as a function
rather than a method
.
Here's some example of what I'm trying to do:
def execute_method(method):
cls = get_class_from_method(method)
obj = cls()
getattr(obj, method.__name__)()
def get_class_from_method(method):
pass # how?
execute_method(HelloView.say_hello)