read_graph6#

read_graph6(path)[源代码]#

从路径中读取以图6格式表示的简单无向图。

参数
path文件或字符串

要写入的文件或文件名。

返回
G图表或图表列表

如果文件包含多行,则返回图表列表

加薪
NetworkXError

如果无法以graph6格式分析字符串

工具书类

1

图6规格<http://users.cecs.anu.edu.au/~bdm/data/formats.html>

实例

您可以通过提供文件路径来读取graph6文件:

>>> import tempfile
>>> with tempfile.NamedTemporaryFile() 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)]