First try pickle ; It is designed to serialize arbitrary objects.
Example of creating DiGraph and serializing to a file:
import pickle import networkx as nx dg = nx.DiGraph() dg.add_edge('a','b') dg.add_edge('a','c') pickle.dump(dg, open('/tmp/graph.txt', 'w'))
Example loading a DiGraph from a file:
import pickle import networkx as nx dg = pickle.load(open('/tmp/graph.txt')) print dg.edges()
Output:
[('a', 'c'), ('a', 'b')]
If this is not efficient enough, I would write my own procedure for serialization:
- ribs and
- (in case a node has no boundaries).
Note that using lists, when possible, can be much more efficient (instead of the standard for loops).
If this is not efficient enough, I would call the C ++ routine from Python: http://docs.python.org/extending/extending.html
user
source share