callable(object):
这个函数的作用是检查一个对象是否可以调用的。如果返回True,object仍然可能调用失败。但是返回False,则调用object一定不会成功。
需要注意的是:类是可以调用的,类的调用返回这个类的一个实例。而类的实例需要定义了__call__()才可以调用。
例子:
class example:
def __call__(self):
print 'called'
test = example() #produce an instance of a class
test() #the output is called
callable(example) #the output is True
callable(test) #the output is True, if not define __call__ function, the output is False