Suppose I have this class:
class Foo(): def foo_method(self): pass Now suppose I have an object foo = Foo(). I can pass foo.foo_method around as argument to a function. foo.foo_method.__qualname__ returns the string representing the method's "full name": "Foo.foo_method". What if I want to get Foo, the class itself, from foo.foo_method?
The solution I came up with is:
def method_class(method): return eval(method.__qualname__.split(".")[0]) Is there a less "dirty" way of achieving this?
dir(foo)orhelp(foo)print either of those and try__self__offoo_method?