简体   繁体   English

Networkx AttributeError: 'DiGraph' object 在继承上没有属性 '_succ'

[英]Networkx AttributeError: 'DiGraph' object has no attribute '_succ' on inheritence

Why does the following code为什么会出现下面的代码

import networkx as nx

class DiGraph(nx.DiGraph):
    def __init__(self):
        self.add_node("a")
        super().add_node('a')

d  = DiGraph()

produce an attribute error产生属性错误

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/tmp/ipykernel_9038/3565896072.py in <module>
      6         super().add_node('a')
      7 
----> 8 d  = DiGraph()

/tmp/ipykernel_9038/3565896072.py in __init__(self)
      3 class DiGraph(nx.DiGraph):
      4     def __init__(self):
----> 5         self.add_node("a")
      6         super().add_node('a')
      7 

/usr/lib/python3/dist-packages/networkx/classes/digraph.py in add_node(self, node_for_adding, **attr)
    418         doesn't change on mutables.
    419         """
--> 420         if node_for_adding not in self._succ:
    421             self._succ[node_for_adding] = self.adjlist_inner_dict_factory()
    422             self._pred[node_for_adding] = self.adjlist_inner_dict_factory()

AttributeError: 'DiGraph' object has no attribute '_succ'

My.networkx version is 2.4 My.networkx 版本是 2.4

import networkx as nx

class CusDiGraph(nx.DiGraph):
    def __init__(self):
        super(CusDiGraph, self).__init__()
        self.add_node("a")
        super().add_node('a')

d = CusDiGraph()


# plt
import matplotlib.pyplot as plt
pos=nx.spring_layout(d) # pos = nx.nx_agraph.graphviz_layout(G)
nx.draw_networkx(d,pos)
labels = nx.get_edge_attributes(d,'weight')
nx.draw_networkx_edge_labels(d,pos,edge_labels=labels)

Just change the inheritance relationship.只需更改 inheritance 关系即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 networkx DiGraph 属性错误 self._succ - networkx DiGraph Attribute Error self._succ AttributeError: &#39;DiGraph&#39; 对象没有属性 &#39;number_of_selfloops&#39; - AttributeError: 'DiGraph' object has no attribute 'number_of_selfloops' AttributeError:&#39;module&#39;对象没有networkx库的属性&#39;write_dot&#39; - AttributeError: 'module' object has no attribute 'write_dot' for networkx library AttributeError: &#39;set&#39; 对象没有与 NetworkX 一起使用的属性 &#39;number_of_nodes&#39; - AttributeError: 'set' object has no attribute 'number_of_nodes' working with NetworkX AttributeError:&#39;module&#39;对象没有networkx 1.11属性&#39;graphviz_layout&#39; - AttributeError: 'module' object has no attribute 'graphviz_layout' with networkx 1.11 有向图 object 没有属性“add_path” - digraph object has no attribute 'add_path' AttributeError:模块“networkx”没有属性“utils” - AttributeError: module 'networkx' has no attribute 'utils' AttributeError: 模块“networkx”没有属性“Graph” - AttributeError: module 'networkx' has no attribute 'Graph' AttributeError: 'AttributeError' object 没有属性 'To' - AttributeError: 'AttributeError' object has no attribute 'To' AttributeError: &#39;对象没有属性&#39; - AttributeError: 'Object has no attribute'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM