[英]networkx: 'super' object has no attribute 'node'
我嘗試從networkx.DiGraph擴展一個類
import networkx as nx
class branch(nx.DiGraph):
def __init__(self,g,raiz):
self.b=super(branch,self)
self.b.__init__(g)
self.r = raiz
def strong(self):
print self.b.nodes(),self.b.node[self.r]
if self.b.node[self.r]['w']>0:
return 1
else:
return 0
如果執行,我得到
[1, 'r']
...
AttributeError: 'super' object has no attribute 'node'
我可以使用.nodes()
但不能使用.node[]
,為什么?
很簡單,因為node[]
不存在。 相反, nodes()
返回一個可以用[]
進行索引的數組。 用於此的代碼可能類似於self.b.nodes()[self.r]
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.