Python Forum
This constructor takes no arguments
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
This constructor takes no arguments
#1
Hi all,

i am just learning about classes. This a very simplified version of the example i was checking in a book

class Person:
    def __ini__(self, name):
        self.name = name
once i try to create an instance from this class
person1 = Person('John')
i get the following error :

Error:
Traceback (most recent call last): File "<pyshell#2>", line 1, in <module> person1 = Person('John') TypeError: this constructor takes no arguments
can you please advise what is the problem here.
i have read similar thread but in ost of them the user used only single underscore _init_ instead of double __init__

thanks in advance
Reply
#2
You are missing the t on init
Quote:
def __ini__(self, name):
Recommended Tutorials:
Reply
#3
Wall

thanks metulburr for the very quick help.
that was a stipid mistake from me :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [split] Class takes no arguments bily071 2 598 Oct-23-2023, 03:59 PM
Last Post: deanhystad
  Why doesn't calling a parent constructor work with arbitrary keyword arguments? PurposefulCoder 4 870 Jun-24-2023, 02:14 PM
Last Post: deanhystad
  Error TypeError: output_type_handler() takes 2 positional arguments but 6 were given paulo79 1 1,858 Oct-17-2022, 06:29 PM
Last Post: paulo79
  Not including a constructor __init__ in the class definition... bytecrunch 3 11,521 Sep-02-2021, 04:40 AM
Last Post: deanhystad
  Checking the number of arguments a function takes Chirumer 3 2,113 Jul-06-2021, 04:56 PM
Last Post: Chirumer
  Class Takes No Arguments horuscope42 4 4,754 Oct-26-2020, 11:10 PM
Last Post: not_username1234
  syntaxerror when entering a constructor MaartenRo 2 1,941 Aug-03-2020, 02:09 PM
Last Post: MaartenRo
  Class takes no arguments Nazartfya 2 4,505 Jun-27-2020, 12:45 PM
Last Post: Nazartfya
  Why Car() takes no arguments louis216 2 2,546 Jun-25-2020, 03:16 AM
Last Post: louis216
  random.choice() takes two positional arguments, but three were given. ShakeyPakey 5 11,489 May-31-2020, 03:13 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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