Marks
课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)
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()
我在运行这个函数时收到一个错误,告诉我传递来自我只想调用 Sid 的学生类的 Sage。第一次使用多重继承时,相同的函数与其他类一起工作正常,我该怎么办?
(Sid,Sname,Sage)
(Cid,Cname,Cstudents)
。答案 0 :(得分:1)
您的模型似乎不太好,Mark
IS 既不是学生又不是课程(例如牛 IS 是动物),但是标记是由 Student
和 Course
的相关性定义的,因此它可以将它们作为属性。
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)
该调用现在是连贯的
marks = Marks(int(Sid), int(Cid), int(Mark))