2015-10-06 103 views
2

我想一些额外的属性添加到pyTreenode类实现决策树算法。扩展新的风格

对于用户定义的内容,它只有一个data属性,这也是使用类方法getNode(content)时搜索的属性。我想在那里存储一个唯一的ID,但是也存储了用于树计算的其他属性。

我试着做各种各样的事情,但它从this post出现,下列应该是做的方式:

from pyTree.Tree import Tree 

class decTree(Tree): 
    def __init__(self, val1, val2, data=None, children=None,): 
     super(decTree, self).__init__(data=None, children=None) 
     self.val1 = val1 
     self.val2 = val2 

if __name__ == '__main__': 
    tree = decTree(val1=1.5, val2='string', data='567') 

导致以下属性的错误:

TypeError: super() takes at least 1 argument (0 given) 

有关执行此操作或其他事项需要考虑的任何建议都很棒。谢谢!

+2

什么是异常的**完整**回溯?很显然'TypeError'不是源于你在这里使用'super()',你有两个参数。 –

+0

'pyTree'需要Python 3或更新版本。 –

回答

3

您对Python的使用2 pyTree;但该项目仅适用于Python 3的

PyPI page

A list-derived TREE data structure in Python 3

super()在Python 3不带参数的方法中使用时,和that's what the pyTree project does。这使得代码库与Python 2

你是正确的,否则扩展类不兼容;您的代码在与Python 3一起使用时可以工作。