错误描述
我用的版本是python2.7+networkx2.2。部分代码:
#G2是传入的一个随机网络
unsaturated_b = G2.nodes()
unsaturated_b.remove(node_b)
最后一行报错,提示AttributeError: 'NodeView' object has no attribute 'remove'
解决办法
这是由于networkx1.x和networkx2.x版本不同而导致的,因为没有使用列表而是NodeView。
可以转换为列表 list(G.nodes())
unsaturated_b = G2.nodes()
list(unsaturated_b).remove(node_b)
更多信息:
https://networkx.github.io/documentation/latest/release/migration_guide_from_1.x_to_2.0.html