求问。。。这个错误是怎么搞的?

weixin_41744323 2018-02-19 01:04:05
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"]) #TypeError

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()

>>>TypeError:object.new_( ) takes no parameter
...全文
1565 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
陈年椰子 2018-02-19
  • 打赏
  • 举报
回复
构造函数是
__init__
你写的是
_init_
前后是两个下划线 。
陈年椰子 2018-02-19
  • 打赏
  • 举报
回复
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"])   #TypeError

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()

37,718

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧