Search code examples
pythontypeerrormagic-methods

object takes no parameters


I'm getting the above error when I run the following code:

class Song(object):
    def _init_(self,lyrics):
        self.lyrics=lyrics

happy_bday = Song([ "happy birthday to you.",
                    "i don't want to get sued.",
                    "so i will stop right here."])

When I run it from PowerShell I get this error:

Traceback (most recent call last):
 File "qa.py", line 12, in <module>
    "so i will stop right here".])
TypeError:object() takes no parameters

Solution

  • Your init method needs 2 _ on either side, not just 1

    def __init__(self, lyrics):