2017-02-07 1 views
1

무슨 일이 일어나고있는 중입니다. 스택 오버플로에 대한 다른 솔루션을 살펴 보았지만 비 보았습니다. 기본 속성의 값을 변경하는 메소드가있는 기본 객체가 있습니다. 사과, 내가 원래 자체에 전달되지 않는다 : 나는 아이 클래스 (상속)에서 기본 함수를 호출 할 때 나는 자식 클래스는 속성 "baseAttribute"하위 클래스 파이썬에서 기본 클래스 메서드 호출

class GameObject(object): 
#This is the base class for gameObjects 
def __init__(self): 
    self.components = {} 

def addComponent(self, comp): 
    self.components[0] = comp #ignore the index. Placed 0 just for illustration 

class Circle(GameObject): 
#circle game object 
def __init__(self): 
    super(GameObject,self).__init__() 
    #PROBLEM STATEMENT 
    self.addComponent(AComponentObject()) 
    #or super(GameObject,self).addComponent(self,AComponentObject()) 
    #or GameObject.addComponent(self, AComponentObject()) 

편집이 없음을 얻는다.

+0

놀랍도록 받아 들일 만합니다 ;-) – GhostCat

답변

4

간단한이 - 두 번째 자기 생략 : 당신이 볼

self.addComponent(AComponentObject()) 

을, 위의 사실 즉

addComponent(self, AComponentObject()) 

로 변환 : 기능에서 작동 본질 "OO"에서 이 그 암시 적/자기 포인터 (그러나 사용자 이름)를 인수로 사용합니다.

0

.addComponent() 방법에 대해 잘못된 인수를 사용하고 있습니다.

# ... 

class Circle(GameObject): 

def __init__(self): 
    super(GameObject,self).__init__() 
    # NOT A PROBLEM STATEMENT ANYMORE 
    self.addComponent(AComponentObject()) 
    # ... 
관련 문제