Warning

This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.

networkx.MultiGraph.get_edge_data

MultiGraph.get_edge_data(u, v, key=None, default=None)[source]

Return the attribute dictionary associated with edge (u, v).

This is identical to G[u][v][key] except the default is returned instead of an exception is the edge doesn’t exist.

Parameters:
  • u, v (nodes)
  • default (any Python object (default=None)) – Value to return if the edge (u, v) is not found.
  • key (hashable identifier, optional (default=None)) – Return data only for the edge with specified key.
Returns:

edge_dict – The edge attribute dictionary.

Return type:

dictionary

Examples

>>> G = nx.MultiGraph() # or MultiDiGraph
>>> key = G.add_edge(0, 1, key='a', weight=7)
>>> G[0][1]['a']  # key='a'
{'weight': 7}
>>> G.edges[0, 1, 'a']  # key='a'
{'weight': 7}

Warning: we protect the graph data structure by making G.edges[1, 2, key] and G[1][2][key] read-only dict-like structures. You need to specify all edge info to assign to the edge data associated with that edge.

>>> G[0][1]['a']['weight'] = 10
>>> G.edges[0, 1, 'a']['weight'] = 10
>>> G[0][1]['a']['weight']
10
>>> G.edges[1, 0, 'a']['weight']
10
>>> G = nx.MultiGraph() # or MultiDiGraph
>>> nx.add_path(G, [0, 1, 2, 3])
>>> G.get_edge_data(0, 1)
{0: {}}
>>> e = (0, 1)
>>> G.get_edge_data(*e) # tuple form
{0: {}}
>>> G.get_edge_data('a', 'b', default=0) # edge not in graph, return 0
0