Ok so I have been hunting around for awhile, please excuse the fact that this is probably a fairly simple question, but no matter how many threads I read of the same error type, I can't figure out what I am doing wrong. I am missing something conceptually I believe.
Here is the code:
class Song(object): def __init__ (self, lyrics, feliz): self.lyrics = lyrics self.feliz = "feliz navidad, etc etc" def sing_me_a_song(self): for line in self.lyrics: print line happy_bday = Song(["\n\nHappy birthday to you", "I don't want to get sued", "So I'll stop right there.\n\n\n"]) bulls_on_parade = Song(["They rally around the family", "With pockets full of shells.\n"]) happy_bday.sing_me_a_song() bulls_on_parade.sing_me_a_song() songz = Song() print songz.feliz() Here is the error I get:
Traceback (most recent call last): File "ex40.py", line 13, in <module> "So I'll stop right there.\n\n\n"]) TypeError: __init__() takes exactly 3 arguments (2 given) I realize this is probably dumb, but I am hung up on this and would really like some help. If it means anything this is obviously from LPTHW and I have editted lesson 40, the code words fine if i remove all the references to feliz, that was me trying to add my own variable to the class Song and then have it print out at the end. Thank you in advance.
So I can make it do what I want by adding the following:
feliz_navidad = Song(["Feliz navidad", "Feliz navidad", "Prospero anos delicidad.\n"]) feliz_navidad.sing_me_a_song() But, is there no other way for me to use the class to have it print a string than to use the defined sing_me_a_song function?
I was attempting to reference the Song class and have it print out a string without using a function defined inside... I suppose that is a dumb thing to do. I misunderstood how it works...
__init__method asks for two arguments (selfis passed implicitly), but you only give it one. You never usefeliz.