read_pajek#
- read_pajek(path, encoding='UTF-8')[source]#
Read graph in Pajek format from path.
- Parameters:
- pathfile or string
Filename or file handle to read. Filenames ending in .gz or .bz2 will be decompressed.
- Returns:
- GNetworkX MultiGraph or MultiDiGraph.
References
See http://vlado.fmf.uni-lj.si/pub/networks/pajek/doc/draweps.htm for format information.
Examples
>>> from pathlib import Path >>> import tempfile >>> tmp_path = Path(tempfile.gettempdir())
>>> fpath = tmp_path / "test.net" >>> nx.write_pajek(nx.path_graph(4), fpath) >>> G = nx.read_pajek(fpath) >>> G.edges MultiEdgeView([('0', '1', 0), ('1', '2', 0), ('2', '3', 0)])
To create a Graph instead of a MultiGraph use
>>> G1 = nx.Graph(G) >>> G1.edges EdgeView([('0', '1'), ('1', '2'), ('2', '3')])