Kittens
Kittens

Reputation: 3

TypeError: __init__() missing 1 required positional argument: 'Sage'

Marks class

from Studentclass import Student
from Courseclass import Course

class Marks(Student, Course):
    def __init__(self, Sid,Cid, Mark):
        super().__init__(Sid,Cid)#Error line 7, in __init__ super().__init__(Sid,Cid) TypeError: __init__() missing 1 required positional argument: 'Sage'#
        self.Mark = Mark

    def __repr__(self):
        return '({},{},{})'.format(self.Sid, self.Cid, self.Mark)

Main code

from Studentclass import Student
from Courseclass import Course
from Marksclass import Marks

def read_populate_marks():
    with open("Marks.txt", "r") as m:
        marks_list = []
        for line in m:
            Sid, Cid, Mark = line.split(",")
            marks = Marks(int(Sid), int(Cid), int(Mark))#Error line 37
            marks_list.append(marks)
        return marks_list

print(read_populate_marks()

I am receiving an error when running this function telling me to pass Sage which is from the student class I only wish to call Sid. the same function works fine with other classes first time using multiple inheritance what should I do?

Upvotes: 0

Views: 394

Answers (1)

azro
azro

Reputation: 54148

It seems that your model isn't good, a Mark IS not both a Student and a Course (like a Cow IS an Animal), but the Mark is defined by the correlation of a Student and Course so it may have them as attributes.

class Marks:
    student_id: int
    course_id: int
    mark = int

    def __init__(self, Sid, Cid, Mark):
        super().__init__()
        self.student_id = Sid
        self.course_id = Cid
        self.mark = Mark

    def __repr__(self):
        return '({},{},{})'.format(self.student_id, self.course_id, self.mark)

That call is now coherent

marks = Marks(int(Sid), int(Cid), int(Mark))

Upvotes: 1

Related Questions