3
아래 그림과 같이 부모 클래스와 자식 클래스를 만들면 부모 클래스의 인수가 자동으로 자식 클래스에서 가져 오지 않는 이유는 무엇입니까?이유는 파이썬 클래스/하위 클래스 상속 뒤에
class testParent(object):
def __init__(self,testParentParam1,testParentParam2):
pass
class testChild(testParent):
def __init__(self,testParentParam1,testParentParam2,testChildParam1,testChildParam2):
pass
이 코드보다 더 나은가요 ...
class testParent(object):
def __init__(self,testParentParam1,testParentParam2):
pass
class testChild(testParent):
def __init__(self,testChildParam1,testChildParam2):
pass
생성자가 비어있는 동안 어떤 것이 더 좋은지 알기 어렵습니다. – bereal
두 가지 모두 작동 할 수 있으며, 수행하려는 작업에 따라 다릅니다. 문제가있는 곳을 파악할 수있는 충분한 정보가 없습니다. – cmd
필자가 작성한 (필자 자신의 '__init__'을 필요로하는) 하위 클래스는 수퍼 클래스와 동일한 인수를 받아 들여 수정되지 않은 채로 전달했습니다. 대다수는 더 적은 인수 또는 다른 인수를 수용했습니다 (그리고 어떻게 든 수퍼 클래스에 전달할 인수를 계산했습니다). – delnan