Class-Aggregation and creating a list/dictionary - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Class-Aggregation and creating a list/dictionary (/thread-35147.html) |
Class-Aggregation and creating a list/dictionary - IoannisDem - Oct-03-2021 Hello I am creating three classes and I try to use aggregation/association between them for inheritance. The first class has the info of the student (Student class), the second one has the subject info (Cousre class) and the grades of a students - Grdes class (used association between student and course class). Now I try to use aggregation between the grades class and the course class. The methods of the Course class are: subject, name and grade Thus I want to creata a dictionary in the Grades class, which stores the name as key and the grades as values of the students. How can I do this with aggregation. I though of creating a library in a class but not in any method and use this "Grades.dictionary" to call it. It seems though, when I try to use the name of a student (using a Course-object) in the dictionary created I get this: <bound method Course.get_student_name of <__main__.Course object at 0x00000279478578E0>> So it returns this instead of the student's name thus I cannot use the dictionary. Thank you in advance! RE: Class-Aggregation and creating a list/dictionary - Yoriz - Oct-03-2021 If you don't call a method with () you get the memory address class Course: def get_student_name(self): return "get_student_name" course = Course() print(course.get_student_name) call the methodprint(course.get_student_name())
|