我通過networkX教程工作的關鍵錯誤,九頁是這樣的:NetworkX教程提供超值的選擇
>>> g = nx . Graph()
>>> g . add_node (1 , name = ‘ Obrian ’)
>>> g . add_nodes_from ([2] , name = ‘ Quintana ’ ])
>>> g [1][ ‘ name ’]
‘ Obrian ’
我在代碼重構:
import networkx as nx
g = nx.Graph()
g.add_node(1,name='Obrian')
g.add_nodes_from([2],name='Quintana')
print "Node 1 name: " + g[1]['name']
,然而對於一些原因,這個簡單的5行腳本dosn't運行:
Traceback (most recent call last):
File "NetTest[nx_tut]--[P09].py", line 9, in <module>
print "Node 1 name: " + g[1]['name']
KeyError: 'name'
我覺得我失去了一些真正明顯的東西。它是什麼?
我認爲它應該是:'g.node [1] ['name']' – bernie