내가 메타 클래스를 가지고 말 ProductClass의 __init__
이 (가) 트리거 되었습니까? Meta의 __call__
때문에?메타 클래스의 "__call__"및 제품 수준의 "__init__"
UPDATE :
지금, 나는 ProductClass에 대한 __new__
를 추가는 전화 메타의 __call__
의 책임
class ProductClass(object):
__metaclass__ = Meta
def __new__(cls, *args):
print "ProductClass: __new__ with", args
return super(ProductClass, cls).__new__(cls, *args)
def __init__(self, *args):
print "ProductClass: __init__ with", args
p = ProductClass(1)
가 ProductClass의 __new__
및 __init__
?
을 제가 ProductClass에서 "__new__"을 가지고 있다면? Meta의 "__call__"은 ProductClass의 "__new__"과 "__init__"을 호출합니까? 내 업데이트를 참조하십시오. – Alcott
그리고 분명히 Meta의 "__call__"이 ProductClass의 "__new__"보다 먼저 호출됩니다. – Alcott
문제는'ProductClass .__ new__'와'ProductClass .__ init__'을 호출하기 위해'Meta .__ call__'이 필요하다는 것입니다. 일반적으로'type .__ call__'은 당신을 대신하지만,'Meta .__ call__'을 정의 할 때 그 행동을 덮어 씁니다. 그렇게하지 않으면 실행되지 않습니다. 그래서, 당신은 스스로 __new__와 __init__를 호출하거나, type .__ call __ (cls, * args)와 같은 것을 호출 할 필요가 있습니다. –