fork(1) download
  1. class Call:
  2. def __call__(self):
  3. pass
  4.  
  5. class Foo:
  6. def __init__(self):
  7. self.var = Call()
  8.  
  9. def method(self):
  10. pass
  11.  
  12. foo = Foo()
  13.  
  14.  
  15.  
  16. def method_exists(instance, method):
  17. return method in dir(instance) and callable(instance.method)
  18.  
  19.  
  20. print(method_exists(foo, "method"))
  21. print(method_exists(foo, "var"))
Success #stdin #stdout 0.02s 27712KB
stdin
Standard input is empty
stdout
True
True