运行以下代码时出现上述错误:
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."])
当我从PowerShell运行它时出现此错误:
Traceback (most recent call last):
File "qa.py", line 12, in <module>
"so i will stop right here".])
TypeError:object() takes no parameters
答案 0 :(得分:2)
您的init
方法需要2 _
,而不仅仅是1
def __init__(self, lyrics):
答案 1 :(得分:0)
再次检查您的源代码。错误消息与您的来源之间存在差异。你的消息来源说:
"so i will stop right here."])
但是您的错误消息显示:
"so i will stop right here".])
一段时间以外而不是引号内部相当重要!