2015-10-06 149 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一起使用時可以工作。