def set_edge(graph, s, t, attrs):
"""Set edge attrs.
Parameters
----------
graph : networkx.(Di)Graph
s : hashable, source node id.
t : hashable, target node id.
attrs : dictionary
Dictionary with attributes to set.
Raises
------
GraphError
If an edge between `s` and `t` does not exist.
"""
new_attrs = deepcopy(attrs)
if not graph.has_edge(s, t):
raise GraphError(
"Edge %s->%s does not exist" % (str(s), str(t)))
normalize_attrs(new_attrs)
graph.edge[s][t] = new_attrs
if not graph.is_directed():
graph.edge[t][s] = new_attrs
评论列表
文章目录