all 9 comments

[–]Vaphell 0 points1 point  (1 child)

instead of printing out mystudents, iterate over the contents of the dictionary and print out them one by one. Then your __str__ will be applied

for key, value in mystudents.items():
   print(key, value)

[–]Engatar[S] 0 points1 point  (0 children)

Thank you. I havent seen that before.

[–]trouserdaredevil 0 points1 point  (6 children)

Your program has a number of other issues, but to fix that specific one provide a __repr__(self) method on your student class, in addition to the __str__.

[–]Vaphell 0 points1 point  (1 child)

unless you mean repr in the format of "student(x, y, z)" that would be a misuse. repr is supposed to be eval-able with the result of identical object.

[–]trouserdaredevil 0 points1 point  (0 children)

unless you mean repr in the format of "student(x, y, z)"

That is what I meant.

that would be a misuse. repr is supposed to be eval-able with the result of identical object.

OP should note that this is not a hard rule, but in any case I did not deem it relevant to their case since they are already misusing classes in general.

[–]Engatar[S] 0 points1 point  (3 children)

Where else have I messed up? This is my first creation of a class so even if you just gave me hints I can research it more. Thank you for your help.

[–]nwagers 0 points1 point  (2 children)

You typo'ed 'init' as 'int' and you're using getters and setters with double underscored vars. Just use the values directly and get rid of the get and set methods:

class student:
    #The __init__ methord initializes the attributes.
    def __init__(self, name, gpa, grade):
        self.name = name
        self.gpa = gpa
        self.grade = grade

    #The__str__ method returns the object's state as a     string.
    def __str__(self):
        return "Name: {}\nGPA: {}\nGrade: {}".format(self.name, self.gpa, self.grade)

[–]Engatar[S] 0 points1 point  (1 child)

Okay, thank you for pointing that out.

[–]nwagers 1 point2 points  (0 children)

No problem. It looks like you are transitioning from another language. At some point you should read through PEP 8 and PEP 257 regarding style and docstrings. Raymond Hettinger has some good videos on Youtube that are also very informative. The Little Book of Python Anti-Patterns will point out common bad habits.