How to add a class instance from user input in python?
<pre><code>class Student(object):
    def __init__(self, name, chinese = 0, math = 0, english = 0):
        self.name = name
        self.chinese = chinese
        self.math = math
        self.english = english
        self.total = self.chinese + self.math + self.english
        Student.list.append(name)'
</code></pre>

<p>I'm trying to write a grade management system, all the student's score are stored in classes of their name. How can I add new instances to the class Student based on user input?</p>

<pre><code>    name = raw_input("Please input the student's name:")
    chinese = input("Please input Chinese score:")
    math = input("Please input Math score:")
    english = input("Please input English score:")
    name = Student(name, chinese, math, english)
    # eval(name)
    # name = Student(name, chinese, math, english)
</code></pre>

<p>I've tried with these method but nothing works out.</p>

<p>Try doing it the following way. :</p>

<pre><code>from collections import defaultdict
class Student:

    def __init__(self, name=None, chinese=None, math=None, english=None):
        self.student_info = defaultdict(list)
        if name is not None:
            self.student_info['name'].append(name)
            self.student_info['chinese'].append(chinese)
            self.student_info['math'].append(math)
            self.student_info['english'].append(english)

    def add_student(self, name, chinese, math, english):
        if name is not None:
            self.student_info['name'].append(name)
            self.student_info['chinese'].append(chinese)
            self.student_info['math'].append(math)
            self.student_info['english'].append(english)
        return None
</code></pre>

<p>In your original question's code, there is no add method (just one constructor). Hence you cannot add any new student's information to the object. </p>

python