List appended in function doesn't work
<p>This is my class:</p>

<pre><code>from Student import Student
class Class:
    stulist=[]
    def __init__ (self, classname, numstudents):
        self.classname=classname
        self.numstudents=numstudents
    def addStudent(self, stuNum, stuName, stuGrades):
        Class.stulist.append(Student(stuName, stuGrades))
    def getPlace(self):
        print (Class.stulist[0].printLn()) #printLn is function in Student 
        print (Class.stulist[1].printLn())
        print (Class.stulist[2].printLn())
</code></pre>

<p>This is my runner:</p>

<pre><code>from Class import Class

class ClassRunner():
        def main():
            test=Class("Comp sci 1", 3)
            test.addStudent(0, "Jimmy","4 - 100 90 80 60")
            test.addStudent(1, "Sandy","4 - 100 100 80 70")
            test.addStudent(2,"Fred","4 - 50 50 70 68")
            test.getPlace()
        main()
</code></pre>

<p>my output shows:</p>

<p>Fred = 50 50 70 68</p>

<p>Fred = 50 50 70 68</p>

<p>Fred = 50 50 70 68</p>

<p>But i want it to show:</p>

<p>Jimmy = 100 90 80 60</p>

<p>Sandy = 100 100 80 70</p>

<p>Fred = 50 50 70 68</p>

<p>what am I doing wrong? Thank you!</p>

<p>In your <code>Class</code> class, <code>self.stulist</code> instead of <code>Class.stulist</code>. </p>

<p>You are modifying the class itself, not the instance variable.</p>

<pre><code>class Class:
    stulist=[]
    def __init__ (self, classname, numstudents):
        self.classname=classname
        self.numstudents=numstudents
    def addStudent(self, stuNum, stuName, stuGrades):
        self.stulist.append(Student(stuName, stuGrades))
    def getPlace(self):
        print (self.stulist[0].printLn()) #printLn is function in Student 
        print (self.stulist[1].printLn())
        print (self.stulist[2].printLn())
</code></pre>

<p>References to <code>Class</code> are going to modify the actual <code>Class</code> object itself.</p>

python