read_edgelist

1,001 views
Skip to first unread message

Francesc Segura

unread,
Jul 13, 2011, 6:24:24 PM7/13/11
to networkx-discuss
Hello,

I create a .dat file with the data of my graph by using:

nx.write_edgelist(best_graph,'optimal-graph.dat')

But then, if I try to read it with the command:

G=nx.read_edgelist("optimal-graph.dat")

It gives an error like this one:

"Failed to convert edge data (%s) to dictionary."%(d))
TypeError: Failed to convert edge data ([u'(7,', u'4)', u'{}']) to
dictionary."

The file data has an aspect like this:

(7, 3) (14, 11) {}
(7, 3) (9, 1) {}

It is due to the data format? What can I do to read properly the data
in the file?

Aric Hagberg

unread,
Jul 13, 2011, 6:32:28 PM7/13/11
to networkx...@googlegroups.com

The problem is that the default delimiter is whitespace. You can
change that by using, e.g. a tab (or some other symbol)
nx.write_edgelist(G,'file.dat',delimiter='\t') and then the same on
read_edgelist()
Aric

Francesc Segura

unread,
Jul 13, 2011, 7:27:03 PM7/13/11
to networkx-discuss
Thanks a lot for the help, and I'm so sorry for spamming here, but I'm
new to Python and NetworkX and can't do really anything except from
asking people with knowledge.

On 14 jul, 00:32, Aric Hagberg <ahagb...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages