After working with a number of different occurrences of the same graph G
, I dumped them as txt
files with pickle
using this line:
pickling=pickle.dump(G,open('pickled_G.txt','w')) #Example for one single graph
Now, for purposes of further calculations, I want to load these graphs back into networkx by doing:
work_dir=raw_input('Working directory: ')
for i,file in enumerate(os.listdir(work_dir)):
if file.endswith(".txt"):
filename=os.path.abspath(file)
F = nx.read_gpickle(filename) #Loading graph G back into Python and calling it F
EDIT
I get this error: ImportError: No module named copy_reg
, which points at the line where F=nx.read_gpickle(filename)
.
I assume the problem is that I have a bunch of txt
files and I am trying to load them as if they were gpickle
. If my take is correct, how could I convert my .txt
files into .gpickle
without altering the graph features? This would spare me re-running my simulations.