read_sparse6#

read_sparse6(path)[源代码]#

从path读取sparse6格式的无向图。

参数
path文件或字符串

要写入的文件或文件名。

返回
G图形/多图形或图形/多图形列表

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

加薪
NetworkXError

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

工具书类

1

Sparse6规范<https://users.cecs.anu.edu.au/~bdm/data/formats.html>

实例

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

>>> import tempfile
>>> with tempfile.NamedTemporaryFile() as f:
...     _ = f.write(b">>sparse6<<:An\n")
...     _ = f.seek(0)
...     G = nx.read_sparse6(f.name)
>>> list(G.edges())
[(0, 1)]

您还可以通过提供一个类似于对象的打开文件来读取sparse6文件:

>>> import tempfile
>>> with tempfile.NamedTemporaryFile() as f:
...     _ = f.write(b">>sparse6<<:An\n")
...     _ = f.seek(0)
...     G = nx.read_sparse6(f)
>>> list(G.edges())
[(0, 1)]