def read_gml(path, relabel=False):
"""Read graph in GML format from path.
Parameters
----------
path : filename or filehandle
The filename or filehandle to read from.
relabel : bool, optional
If True use the GML node label attribute for node names otherwise use
the node id.
Returns
-------
G : MultiGraph or MultiDiGraph
Raises
------
ImportError
If the pyparsing module is not available.
See Also
--------
write_gml, parse_gml
Notes
-----
Requires pyparsing: http://pyparsing.wikispaces.com/
The GML specification says that files should be ASCII encoded, with any
extended ASCII characters (iso8859-1) appearing as HTML character entities.
References
----------
GML specification:
http://www.infosun.fim.uni-passau.de/Graphlet/GML/gml-tr.html
Examples
--------
>>> G=nx.path_graph(4)
>>> nx.write_gml(G,'test.gml')
>>> H=nx.read_gml('test.gml')
"""
lines = (unescape(line.decode('ascii')) for line in path)
G = parse_gml(lines, relabel=relabel)
return G
read.py 文件源码
python
阅读 27
收藏 0
点赞 0
评论 0
评论列表
文章目录