-1
我有下面的类和功能在我的程序:Python的类型错误:__init __()到底需要3个参数(4给出)
class RaiseAndTurnOff(Exception):
def __init__(self, value, r1):
self.value = value
r1.turn_off_gracefully()
def __str__(self):
return repr(self.value)
def assert_state(self, state):
if not(self.link.is_in_state(state)):
raise RaiseAndTurnOff("Sanity check error: Link should be %s, but it is not! please check the log file reports. Exiting script" % state, self, self.params)
正如你可以看到我发3个参数。出于某种原因,我得到了以下错误:
File "qalib.py", line 103, in assert_state
raise RaiseAndTurnOff("Sanity check error: Link should be %s, but it is not! please check the log file reports. Exiting script" % state, self, self.params)
TypeError: __init__() takes exactly 3 arguments (4 given)
您的异常和发布的代码不匹配。你是否已经纠正了错误,但忘了重启Python解释器? –
@Martijn彼得斯,但自我的RaiseAndTurnOff是不同于我从功能 – Sarit8
发送的自我是的,这的确是不同的。你现在想做什么,为什么你想要通过一个不同的'自我'?你不能这样做*和*同时创建一个'RaiseAndTurnOff'的实例。 –