Python - TypeError:__ init __()需要2个参数(给定3个),但我给了2个

时间:2012-04-20 12:58:00

标签: python python-2.7

我是Python的新手,所以我尝试了一些代码:

class loesung02(object):
    html = ""
    file1 = ""
    def __init__(self, html, file1):
        self.html = html
        self.file1 = file1
        print html + file1
我称之为:

loesung02("aaaaaaaaaaaa", "bbbbbbbbbbb")

使用Python Shell

但我总是得到ErrorMessage,所以有什么不对吗?

1 个答案:

答案 0 :(得分:0)

您收到了什么错误消息?您的代码在我的计算机上运行完全正常。我正在使用python 2.7.1。你是在一个文件中写了然后运行它还是在解释器中写的?如果是后者,请重新初始化或重新运行解释器,因为可能有其他变量会干扰您的代码。