Python Forum

Full Version: Class-Aggregation and creating a list/dictionary
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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!
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)
Output:
<bound method Course.get_student_name of <__main__.Course object at 0x000002C5FE90C610>>
call the method
print(course.get_student_name())
Output:
get_student_name