Python TypeError:object.\uuuuuu new\uuuuuu()在使用继承时不接受任何参数
哎,, 我很难实现一些事情,我想这应该不难。我已经读了很多帖子,但我还是不明白,虽然可能有人回答了,我可能只是不明白答案:/ 因此,我有一个类,在logics/中定义了一个算法文件Threedpll.py和几个辅助函数Python TypeError:object.\uuuuuu new\uuuuuu()在使用继承时不接受任何参数,python,inheritance,typeerror,Python,Inheritance,Typeerror,哎,, 我很难实现一些事情,我想这应该不难。我已经读了很多帖子,但我还是不明白,虽然可能有人回答了,我可能只是不明白答案:/ 因此,我有一个类,在logics/中定义了一个算法文件Threedpll.py和几个辅助函数 class three_dpll(object): ... def __extend__(self, symbol, value, mod): """ __extend__(symbol, value) - extends the mode
class three_dpll(object):
...
def __extend__(self, symbol, value, mod):
""" __extend__(symbol, value) - extends the model
...
"""
def three_dpll(self, formula, symbols, mod):
""" three_dpll(formula, symbols, mod) - calculates 3-DPLL \n
NOTE: This algorithm should not be overwritten in any derived class!!"""
...
# find unit clause
curr_data = self.__find_unit_clause__(formula, mod)
current_symbol = curr_data[0]
current_symbol_set.add(current_symbol)
current_value = curr_data[1]
if current_symbol != None:
return three_dpll(formula, symbols - current_symbol_set,
self.__extend__(current_symbol, current_value, mod))
...
还有一个逻辑,应该为某个逻辑实现算法,在这里我可以重新定义某些方法,比如logics.three_dpll.py(或任何其他辅助函数)
现在从另一个文件中的函数调用它:
def satisfiable(logic, formula):
""" satisfiable - \
takes a logic and a set of formula and returns true or false"""
# model is empty dictionary
model = {}
# symbols is a set
symbols = set()
my_logic = "logics."+logic # logic is passed as string to the script
__import__(my_logic, fromlist=['three_dpll'])
log = modules[my_logic]
used_logic = log.kleene_logic()
for clause in formula:
ite = iter(clause)
for literal in ite:
symbols.add(abs(literal))
try:
return used_logic.three_dpll(formula, symbols, model)
except FormulaValid.FormulaValid:
return True
我得到的错误是:
in three_dpll
self.__extend__(current_symbol, current_value, mod)) TypeError: object.__new__() takes no parameters
有没有办法解决这个问题 你的第三课堂也有一个第三课堂方法。当你
return three_dpll(...)
您正在创建该类的实例(而不是调用该方法,这可能是您想要做的)。该类没有可以处理您给出的参数的\uuuu init\uuu()
函数。这就是错误消息告诉您的
你想要的可能是
return self.three_dpll(...)
这将调用该方法。如果舒尔解决了您的问题,它就不是舒尔,但这应该可以解释一些问题。您不应该像使用
\uuuuuuu extend\uuuuuu
那样编写\uuuuuuuuuuu魔法
方法,编译器会对它们进行非常特殊的处理。我想您只是想要\u private
(带一个前导下划线)方法。
return self.three_dpll(...)