- 看到如下的结果感觉很奇怪
class A(object):
pass
print(A.__class__) #<class 'type'>
也经常看到别的源码中判断getattr后的结果也是type,发现原来type的隐藏属性
'''
下面两个等价
'''
class A(object):
pass
A = type('A',(object,),{})
print(A.__class__) #<class 'type'>
'''
下面两个等价
'''
#1
class MyType(type):
pass
#2
class Foo(object, metaclass=MyType):
pass
#2
Foo = MyType('Foo', (object,), {})
print(Foo.__class__) #<class '__main__.MyType'>