简体   繁体   中英

networkx: 'super' object has no attribute 'node'

I try extend a class from 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

If I execute I get

[1, 'r']
...
AttributeError: 'super' object has no attribute 'node'

I can use .nodes() but no .node[] , why ?

Simply enough, because node[] doesn't exist. Instead, nodes() returns an array that you can index with [] . The code for this might look something like self.b.nodes()[self.r] .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM