-5

So I am using the hardest way to learn python and I am on exercise 40, and below is the code that we are instructed to write into a file named ex40.py:

class Song(object):

    def _init_(self, lyrics):
        self.lyrics = lyrics

    def sing_me_a_song(self):
        for line in self.lyrics:
            print line

happy_bday = Song(["Happy birthday to you",
                   "I don't want to get sued",
                   "So I'll stop right there"])

bulls_on_parade = Song(["They rally around the family",
                         With pockets full of shells"])

happy_bday.sing_me_a_song()

bulls_on_parade.sing_me_a_song()

Then to run it, I am doing: python ex40.py and I am receiving error:

MacBook-Pro-3:PythonsScripts$ python ex40.py

Traceback (most recent call last):
  File "ex40.py", line 12, in <module>
    "So I'll stop right there"])
TypeError: object() takes no parameters
aznjonn
  • 113
  • 16

2 Answers2

3

You need to have two underscores around magic methods like __init__. That means this:

def _init_(self, lyrics):
    self.lyrics = lyrics

Should become this:

def __init__(self, lyrics):
    self.lyrics = lyrics
Ethan Bierlein
  • 3,353
  • 4
  • 28
  • 42
1

The _init_ function should be __init__.

I can also see, just from syntax highlighting, that the last string you use in the file is missing starting double-quotes

Brian
  • 2,172
  • 14
  • 24