我有一个事物列表,其中一些也可以是函数。如果它是一个函数,我想执行它。为此,我进行类型检查。这通常适用于其他类型,例如str、int或float。但对于函数似乎不起作用:
>>> def f():
... pass
...
>>> type(f)
<type 'function'>
>>> if type(f) == function: print 'It is a function!!'
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'function' is not defined
>>>
有人知道我如何检查函数类型吗?