[英]'Graph' object has no attribute 'nodes_iter' in networkx module python
I have the below function in python2.7 using networkx module which produces the error. 我使用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)
Error: 错误:
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'
Does anybody have any idea what has been wrong? 有谁知道出了什么问题?
You are probably using the pre-release version of networkx-2.0 which has removed the nodes_iter() method and now provides the the nodes() method with the same functionality. 您可能正在使用已删除nodes_iter()方法的networkx-2.0的预发布版本,现在提供具有相同功能的nodes()方法。 See this for details on the networkx-2.0 changes.
请参阅此有关networkx-2.0更改的详细信息。
Just in case the link changes again, I'm going to post the actual solution here for future reference. 为了防止链接再次发生变化,我将在此发布实际解决方案以供将来参考。
From NetworkX 2.0 forward, you should change the following line of code from: 从NetworkX 2.0开始,您应该更改以下代码行:
for n, d in H.nodes_iter(data=True):
to: 至:
for n, d in list(H.nodes(data=True)):
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.