Python Forum

Full Version: Class Object hellp
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, I am new to python and having a few problems I was hoping to find some help with on here.
I am creating a class object and for some reason when I try to create the object I gives an error
saying invalid argument.

I've created a file called students.py holding the following information:

class Student:

    def _init_(self, name, major, gpa):
        self.name = name
        self.major = major
        self.gpa = gpa
And another file named app.py holding the following code:

from students import Student

Student1 = Student("Dan", "CNS", 3.6)


print(Student1.name)
When app.py is run I get the following error message:

Error:
Traceback (most recent call last): File "C:/Users/Maintenance/PycharmProjects/Joyride/students.py", line 10, in <module> student1 = Student("Dan", "CNS", 3.5) TypeError: Student() takes no arguments
Any help would be much appreciated, ive been working on it for a couple days and am at a loss.
I can create a object and then pass data into it using the following:

Student1 = Student()
Student1.name = "Dan"
Student1.major = "CNS"
Student1.gpa = 3.5
I just cant figure out why I cant pass arguments to the object at creation.\
Thanks again for any help that anyone can give me and my apologies for the messy post, this is my first time
posting on a forum for help.
__init__ has two underscores on each side, not one.