Python - test whether object is a builtin function

后端 未结 5 909
面向向阳花
面向向阳花 2020-12-19 06:16

Is there a nice way to check whether object o is a builtin Python function?

I know I can use, for example

type(o) == type(pow)

beca

5条回答
  •  [愿得一人]
    2020-12-19 06:48

    Try this:

    >>> import types
    >>> isinstance(pow, types.BuiltinFunctionType)
    True
    >>> def a():
        pass
    >>> isinstance(a, types.BuiltinFunctionType)
    False
    

提交回复
热议问题