2013-04-19 3 views
0

Python에서 상속을 사용하고 있지만 오류가 발생합니다. 수정 방법을 모르므로 'finalStore'객체에 'marone'속성이 없습니다. . 나는 객체를 만들려고 할 때 이것을 얻는다.Python 오류 : 'finalStore'객체에 'name'속성이 없습니다.

from ClassFile import studStore 

class finalStore (studStore): 

    grandAve = 0 
    numStu = 0 

    def __init__(self, name, marone, martwo, marthree, marfour, corone, cortwo, corthree, corfour): 
     studStore.__init__(self, name, marone, martwo, marthree, marfour) 
     self.corone = corone 
     self.cortwo = cortwo 
     self.corthree = corthree 
     self.corfour = corfour 
     finalStore.numStu += 1 
     self.holder = finalStore.numStu 
     self.average = (marone + martwo + marthree + marfour)/4 
     finalStore.grandAve += self.average 
     self.storit = finalStore.grandAve 

내 자식 클래스

class studStore: 

    def __init__(self, name, marone, martwo, marthree, marfour): 
     self.newname = name 
     self.Ave = 0 
     self.marone = marone 
     self.martwo = martwo 
     self.marthree = marthree 
     self.marfour = marfour 

에 대한 초기화 그리고 상위 클래스의 초기화. 난 그냥 아니에요, 나는 오류가 무엇인지 확실하지 않다

listIn.append(finalStore(name, gradeone, gradetwo, gradethree, gradefour, courseOne, courseTwo, courseThree, courseFour)) 

하지만 작동하는 유사한 프로그램을 가지고 내 주요 라인은 내가이 라인에 있지만, 오류에 대한 여러 개체를 만들 단지 루프

내가 슈퍼 클래스의 초기화 기능이

for i in range (0,len(listIn)): 
    print(str(listIn[i].returnName()).ljust(20," "), end = " ") 
    print(str(listIn[i].returnOne()).ljust(20, " ")) 
    print(str(listIn[i].returnTwo()).ljust(20, " ")) 
    print(str(listIn[i].returnThree()).ljust(20, " ")) 
    print(str(listIn[i].returnFour()).ljust(20, " ")) 
+1

오류의 실제 출력을 게시 할 수 있습니까? – Haz

+0

"finalStore"개체에 "marone"속성이 없습니다. –

+0

스택 추적 또는 콘솔에 인쇄되고있는 것이 없습니까? 있다면, 귀하의 게시물에 추가해야합니다. – Haz

답변

0

당신의 전화처럼 * 수입 *에서 출력하고 있습니다 사용하는 것은 올바르지 않습니다. 여기에 어떻게해야합니까 :

class finalStore(studStore): 

    def __init__(self, name, ...): 
     super(finalStore, self).__init__(name, marone, ...) 
+1

그런 식으로 부모 클래스의'__init__' 메소드를 호출하는 것은 잘못되었습니다. 'super'를 사용하면 메소드 확인 순서 (실제로는'studStore'가 아닐 수도 있습니다)에서 다음 클래스의'__init__' 메소드가 호출됩니다. – chepner

관련 문제