A callable is anything that can be called.
The built-in callable (PyCallable_Check in objects.c) checks if the argument is either:
- an instance of a class with a
__call__
method or - is of a type that has a non null tp_call (c struct) member which indicates callability otherwise (such as in functions, methods etc.)
The method named __call__
is (according to the documentation)
Called when the instance is ”called” as a function
Example
class Foo:
def __call__(self):
print 'called'
foo_instance = Foo()
foo_instance() #this is calling the __call__ method