Reputation: 21
I am a new user of python and networkx
and I want to ask you that how to add attributes to graphs,nodes and edges in networkx
?When I try to add it there is an error Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
G[1][3]['color']='blue'
KeyError: 3
I have searched for attribute package for networkx
but not found.
Upvotes: 1
Views: 799
Reputation: 14360
Well it seems your node G[1]
doesn't have four
children (3 wuold be the fourth and 0 the first).
According to the python documetation:
exception KeyError
Raised when a mapping (dictionary) key is not found in the set of existing keys.
In other words G[1][3]
does not exists.
If you are starting to Python, now is a good time to start to learn how to debug your code. That way you will get more tools for findout what's going on with your code.
You can start at: The Python Debugger
or check this question: Python debugging tips
Upvotes: 1