class Call:
def __call__(self):
pass
class Foo:
def __init__(self):
self.var = Call()
def method(self):
pass
foo = Foo()
def method_exists(instance, method):
return hasattr(instance, method) and callable(instance.method)
print(method_exists(foo, "method"))
print(method_exists(foo, "var"))
Y2xhc3MgQ2FsbDoKICAgIGRlZiBfX2NhbGxfXyhzZWxmKToKICAgICAgICBwYXNzCgpjbGFzcyBGb286CiAgICBkZWYgX19pbml0X18oc2VsZik6CiAgICAgICAgc2VsZi52YXIgPSBDYWxsKCkKCiAgICBkZWYgbWV0aG9kKHNlbGYpOgogICAgICAgIHBhc3MKCmZvbyA9IEZvbygpCgoKCmRlZiBtZXRob2RfZXhpc3RzKGluc3RhbmNlLCBtZXRob2QpOgogICAgcmV0dXJuIGhhc2F0dHIoaW5zdGFuY2UsIG1ldGhvZCkgYW5kIGNhbGxhYmxlKGluc3RhbmNlLm1ldGhvZCkKICAgIAoKcHJpbnQobWV0aG9kX2V4aXN0cyhmb28sICJtZXRob2QiKSkKcHJpbnQobWV0aG9kX2V4aXN0cyhmb28sICJ2YXIiKSk=