How to check whether a variable is a class or not?

后端 未结 9 691
暖寄归人
暖寄归人 2020-11-28 19:14

I was wondering how to check whether a variable is a class (not an instance!) or not.

I\'ve tried to use the function isinstance(object, class_or_type_or_tuple

9条回答
  •  忘掉有多难
    2020-11-28 19:16

    There are some working solutions here already, but here's another one:

    >>> import types
    >>> class Dummy: pass
    >>> type(Dummy) is types.ClassType
    True
    

提交回复
热议问题