read_graph6#
- read_graph6(path)[source]#
从 path 读取 graph6 格式的简单无向图。
- 参数:
- path文件或字符串
要读取的文件或文件名。
- 返回值:
- G图或图列表
如果文件包含多行,则返回图列表
- 引发:
- NetworkXError
如果字符串无法以 graph6 格式解析
参考资料
[1]Graph6 规范 <http://users.cecs.anu.edu.au/~bdm/data/formats.html>
示例
可以通过提供文件路径来读取 graph6 文件
>>> import tempfile >>> with tempfile.NamedTemporaryFile(delete=False) as f: ... _ = f.write(b">>graph6<<A_\n") ... _ = f.seek(0) ... G = nx.read_graph6(f.name) >>> list(G.edges()) [(0, 1)]
也可以通过提供一个打开的文件对象来读取 graph6 文件
>>> import tempfile >>> with tempfile.NamedTemporaryFile() as f: ... _ = f.write(b">>graph6<<A_\n") ... _ = f.seek(0) ... G = nx.read_graph6(f) >>> list(G.edges()) [(0, 1)]