easygraph.readwrite.pajek module#
Read graphs in Pajek format.
This implementation handles directed and undirected graphs including those with self loops and parallel edges.
Format#
See http://vlado.fmf.uni-lj.si/pub/networks/pajek/doc/draweps.htm for format information.
- easygraph.readwrite.pajek.generate_pajek(G)[source]#
Generate lines in Pajek graph format.
- Parameters:
G (graph) – A EasyGraph graph
References
See http://vlado.fmf.uni-lj.si/pub/networks/pajek/doc/draweps.htm for format information.
- easygraph.readwrite.pajek.parse_pajek(lines)[source]#
Parse Pajek format graph from string or iterable.
- Parameters:
lines (string or iterable) – Data in Pajek format.
- Returns:
G
- Return type:
EasyGraph graph
See also
- easygraph.readwrite.pajek.read_pajek(path)[source]#
Read graph in Pajek format from path.
- Parameters:
path (file or string) – File or filename to write. Filenames ending in .gz or .bz2 will be uncompressed.
- Returns:
G
- Return type:
EasyGraph MultiGraph or MultiDiGraph.
Examples
>>> G = eg.path_graph(4) >>> eg.write_pajek(G, "test.net") >>> G = eg.read_pajek("test.net")
To create a Graph instead of a MultiGraph use
>>> G1 = eg.Graph(G)
References
See http://vlado.fmf.uni-lj.si/pub/networks/pajek/doc/draweps.htm for format information.
- easygraph.readwrite.pajek.write_pajek(G, path, encoding='UTF-8')[source]#
Write graph in Pajek format to path.
- Parameters:
G (graph) – A EasyGraph graph
path (file or string) – File or filename to write. Filenames ending in .gz or .bz2 will be compressed.
Examples
>>> G = eg.path_graph(4) >>> eg.write_pajek(G, "test.net")
Warning
Optional node attributes and edge attributes must be non-empty strings. Otherwise it will not be written into the file. You will need to convert those attributes to strings if you want to keep them.
References
See http://vlado.fmf.uni-lj.si/pub/networks/pajek/doc/draweps.htm for format information.