-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'的實例。 –