錯誤描述
我用的版本是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