【发布时间】:2011-07-06 14:21:34
【问题描述】:
嘿, 我很难实现一些东西,我想这应该不难。我一直在阅读很多帖子,但我仍然无法弄清楚,虽然它可能已经回答了,我可能只是不明白答案:/
所以,我有一个类,在 logics/ 中定义了一个算法文件 three_dpll.py 和几个辅助函数
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 (或任何其他辅助函数)
from three_dpll import three_dpll
class kleene_logic(three_dpll):
""" This is the definition of Kleene logic """
pass
现在从另一个文件中的函数调用它:
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
关于如何解决这个问题的任何想法?
【问题讨论】:
-
你不应该像使用
__extend__那样编造__magic__方法,它们被编译器非常特殊地对待。我想你只是想要_private(带有一个前导下划线)方法。
标签: python inheritance typeerror