Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 Python 2 中,我可以检查一个类的__metaclass__属性来确定它的元类。
__metaclass__
我如何在 Python 3 中做同样的事情?
使用单参数type函数 ( type(class)),或仅访问class.__class__. 顺便说一句,这两种方法都适用于 Python 2。
type
type(class)
class.__class__
例如,
In [4]: class MyMetaclass(type): pass In [5]: class MyClass(metaclass=MyMetaclass): pass In [6]: type(MyClass) Out[6]: __main__.MyMetaclass