我不知道我的代码是如何从Powershell运行的。它给了我这个错误信息:
Traceback (most recent call last):
File "ex40.py", line 12, in <module>
"So I'll stop right here"])
TypeError: object() takes no parameters
这是我的代码:
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 here"])
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()
我在书中看到了其他完全相同的副本以及我的看法(至少我认为),但他们能够运行。