Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Class Object hellp
#1
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.
Reply
#2
__init__ has two underscores on each side, not one.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Printing out incidence values for Class Object SquderDragon 3 273 Apr-01-2024, 07:52 AM
Last Post: SquderDragon
  error in class: TypeError: 'str' object is not callable akbarza 2 502 Dec-30-2023, 04:35 PM
Last Post: deanhystad
Exclamation win32com: How to pass a reference object into a COM server class Alfalfa 3 4,862 Jul-26-2021, 06:25 PM
Last Post: Alfalfa
  AttributeError class object has no attribute list object scttfnch 5 3,419 Feb-24-2021, 10:03 PM
Last Post: scttfnch
  Python Class and Object Parameters JoeDainton123 5 2,889 Sep-02-2020, 10:43 AM
Last Post: JoeDainton123
  OOP hellp (simple class person) onit 4 2,533 Jul-14-2020, 06:54 PM
Last Post: onit
  Multiprocessing, class, run and a Queue Object SeanInColo 0 1,535 Jul-12-2020, 05:36 PM
Last Post: SeanInColo
  Hi, need help with class, object Houston222 1 1,827 Apr-04-2020, 01:55 PM
Last Post: buran
  class returns NoneType Object istemihan 0 2,243 Aug-12-2019, 11:47 AM
Last Post: istemihan
  Object and type class Uchikago 2 2,226 Jul-28-2019, 10:35 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020