Copy a pygraph, and modify nodes

189 Views Asked by At

I have a pygraph data structure, which I want to modify. I want to perform the following operations:

  1. Create a copy of the existing pygraph
  2. Modify the nodes in the copy, by walking the tree and changing the node attributes

I am unable to find in the documentation/code how to do these operations. Is it possible? How?

1

There are 1 best solutions below

0
On

Copying:

To copy a structure in python you need to make use of the copy module

from copy import deepcopy
copy_graph = deepcopy(original_graph)

Traversing

There is an example on how to traverse the graph:

from pygraph.algorithms.searching import depth_first_search
st, pre, post = depth_first_search(copy_graph)