我正在尝试对networkx Graph对象进行子类化。我的
__init__
只有一个变量传递进去。然而,这意味着当我尝试使用以下调用connected_component_iter
的方法时,可能会出现问题。def connected_component_iter(self):
"""
Yields connected components.
"""
assert self.is_built is True
for subgraph in nx.connected_component_subgraphs(self):
yield subgraph
I get this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "src/unitigGraph.py", line 163, in connected_component_iter
def connected_component_iter(self):
File "/Library/Python/2.7/site-packages/networkx/algorithms/components/connected.py", line 94, in connected_component_subgraphs
yield G.subgraph(c).copy()
File "/Library/Python/2.7/site-packages/networkx/classes/graph.py", line 1486, in subgraph
H = self.__class__()
TypeError: __init__() takes exactly 2 arguments (1 given)
我真的不想删除我的初始化类变量。有没有办法我仍然可以使用Graph
中的connected_component_iter
方法?