networkx: 'super'对象没有'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[]
,这是为什么呢?
1 个回答
0
简单来说,因为 node[]
这个东西是不存在的。相反,nodes()
会返回一个数组,你可以用 []
来访问这个数组里的元素。这个代码可能看起来像 self.b.nodes()[self.r]
。