Read a graph from a list of edges.
Parameters : | path : file or string
comments : string, optional
delimiter : string, optional
create_using : Graph container, optional,
nodetype : int, float, str, Python type, optional
data : bool or list of (label,type) tuples
edgetype : int, float, str, Python type, optional OBSOLETE
encoding: string, optional :
|
---|---|
Returns : | G : graph
|
See also
Notes
Since nodes must be hashable, the function nodetype must return hashable types (e.g. int, float, str, frozenset - or tuples of those, etc.)
Examples
>>> nx.write_edgelist(nx.path_graph(4), "test.edgelist")
>>> G=nx.read_edgelist("test.edgelist")
>>> fh=open("test.edgelist", 'rb')
>>> G=nx.read_edgelist(fh)
>>> fh.close()
>>> G=nx.read_edgelist("test.edgelist", nodetype=int)
>>> G=nx.read_edgelist("test.edgelist",create_using=nx.DiGraph())
Edgelist with data in a list:
>>> textline = '1 2 3'
>>> fh = open('test.edgelist','w')
>>> d = fh.write(textline)
>>> fh.close()
>>> G = nx.read_edgelist('test.edgelist', nodetype=int, data=(('weight',float),))
>>> G.nodes()
[1, 2]
>>> G.edges(data = True)
[(1, 2, {'weight': 3.0})]
See parse_edgelist() for more examples of formatting.