Package networkx :: Package readwrite :: Module gml
[hide private]
[frames] | no frames]

Module gml

source code

Read graphs in GML format. See http://www.infosun.fim.uni-passau.de/Graphlet/GML/gml-tr.html for format specification.

Example graphs in GML format: http://www-personal.umich.edu/~mejn/netdata/




Author: Aric Hagberg (hagberg@lanl.gov)

Functions [hide private]
 
read_gml(path)
Read graph in GML format from path.
source code
 
parse_gml(lines)
Parse GML format from string or iterable.
source code
 
pyparse_gml()
pyparser tokenizer for GML graph format
source code
 
write_gml(G, path)
Write the graph G in GML format to the file or file handle path.
source code
 
_test_suite() source code
Variables [hide private]
  graph = None
Function Details [hide private]

read_gml(path)

source code 

Read graph in GML format from path. Returns an XGraph or XDiGraph.

This doesn't implement the complete GML specification for nested attributes for graphs, edges, and nodes.

parse_gml(lines)

source code 

Parse GML format from string or iterable. Returns an XGraph or XDiGraph.

This doesn't implement the complete GML specification for nested attributes for graphs, edges, and nodes.

pyparse_gml()

source code 

pyparser tokenizer for GML graph format

This doesn't implement the complete GML specification for nested attributes for graphs, edges, and nodes.

write_gml(G, path)

source code 

Write the graph G in GML format to the file or file handle path.

>>> write_gml(G,"file.gml")

path can be a filehandle or a string with the name of the file.

>>> fh=open("file.gml")
>>> write_multiline_adjlist(G,fh)

Filenames ending in .gz or .bz2 will be compressed.

>>> write_multiline_adjlist(G,"file.gml.gz")

The output file will use the default text encoding on your system. It is possible to write files in other encodings by opening the file with the codecs module. See doc/examples/unicode.py for hints.

>>> import codecs
>>> fh=codecs.open("file.edgelist",encoding='iso8859-1')# use iso8859-1
>>> write_edgelist(G,fh)

GML specifications indicate that the file should only use 7bit ASCII text encoding.iso8859-1 (latin-1).

Only a single level of attributes for graphs, nodes, and edges, is supported.