我使用networkx模块在python2.7中有以下函数,产生错误.
for H in networkx.connected_component_subgraphs(G):
bestScore = -1.0
for n, d in H.nodes_iter(data=True):
if d['Score'] > bestScore:
bestScore = d['Score']
bestSV = n
if bestSV is not None:
selectedSVs.add(bestSV)
Run Code Online (Sandbox Code Playgroud)
错误:
Traceback (most recent call last):
File "cnvClassifier.py", line 128, in <module>
for n, d in H.nodes_iter(data=True):
AttributeError: 'Graph' object has no attribute 'nodes_iter'
Run Code Online (Sandbox Code Playgroud)
有谁知道出了什么问题?
万一链接再次更改,我将在此处发布实际的解决方案,以供将来参考。
从NetworkX 2.0向前,您应将以下代码行更改为:
for n, d in H.nodes_iter(data=True):
Run Code Online (Sandbox Code Playgroud)
至:
for n, d in list(H.nodes(data=True)):
Run Code Online (Sandbox Code Playgroud)