How to check for a function type in Python?

后端 未结 4 1058
-上瘾入骨i
-上瘾入骨i 2021-01-13 05:51

I\'ve got a list of things, of which some can also be functions. If it is a function I would like to execute it. For this I do a type-check. This normally works for other ty

4条回答
  •  感动是毒
    2021-01-13 06:14

    collections.Callable can be used:

    import collections
    
    print isinstance(f, collections.Callable)
    

提交回复
热议问题