다음 예제에서는 CL2의 super를 "cl2 test cl5"의 self.test()로 대체하면 동일한 출력을 얻습니다. 수퍼는 정확히 어떤 차이를 만듭니다.파이썬에서 슈퍼가 중복됩니까?
class CL1(object):
def test(self):
print "test cl1"
class CL2(CL1):
def abc(self):
print "in cl2"
super(CL2,self).test()
#self.test()
class CL3(CL1):
def test(self):
print "test cl3"
class CL5(CL1):
def test(self):
print "test cl5"
class CL4(CL2,CL5,CL3):
def add(self):
print 'cl4'
def main()
o=CL4()
o.abc()
if __name__ == "__main__":
main()
흥미로운 질문입니다. "객체"가 아닌 다른 객체를 서브 클래 싱하는 것은 절대적으로 필요합니다. –
'super'의 이름이 잘못되었습니다. 그것은 그것이 사용되는 클래스의 정적으로 정의 된 부모 클래스를 반드시 참조하는 것은 아닙니다. – chepner