fork download
  1. from collections import Callable
  2.  
  3. class C:
  4. pass
  5.  
  6. f = C()
  7. print(callable(f))
  8.  
  9. C.__call__ = lambda *a: "works"
  10. f = C()
  11. print(callable(f))
  12. print(f())
  13.  
  14.  
  15. C.__call__ = "not callable"
  16. f = C()
  17. print(callable(f))
  18. print(isinstance(f, Callable))
  19. print(f())
Runtime error #stdin #stdout #stderr 0.14s 10328KB
stdin
Standard input is empty
stdout
False
True
works
True
True
stderr
Traceback (most recent call last):
  File "prog.py", line 19, in <module>
    print(f())
TypeError: 'str' object is not callable