Warning

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

freeze

freeze(G)[source]

Modify graph to prevent further change by adding or removing nodes or edges.

Node and edge data can still be modified.

Parameters :

G : graph

A NetworkX graph

See also

is_frozen

Notes

To “unfreeze” a graph you must make a copy by creating a new graph object:

>>> graph = nx.path_graph(4)
>>> frozen_graph = nx.freeze(graph)
>>> unfrozen_graph = nx.Graph(frozen_graph)
>>> nx.is_frozen(unfrozen_graph)
False

Examples

>>> G=nx.Graph()
>>> G.add_path([0,1,2,3])
>>> G=nx.freeze(G)
>>> try:
...    G.add_edge(4,5)
... except nx.NetworkXError as e:
...    print(str(e))
Frozen graph can't be modified