前提・我想达到的
我将使用 Python 来读取 GML 文件。
错误信息
Traceback (most recent call last):
File "firstgml.py", line 9, in <module>
G = nx.read_gml(gml_path)
File "<decorator-gen-434>", line 2, in read_gml
File "/Users/XXXX/.pyenv/versions/3.8.5/lib/python3.8/site-packages/networkx/utils/decorators.py", line 227, in _open_file
result = func_to_be_decorated(*new_args, **kwargs)
File "/Users/XXXX/.pyenv/versions/3.8.5/lib/python3.8/site-packages/networkx/readwrite/gml.py", line 218, in read_gml
G = parse_gml_lines(filter_lines(path), label, destringizer)
File "/Users/XXXX/.pyenv/versions/3.8.5/lib/python3.8/site-packages/networkx/readwrite/gml.py", line 398, in parse_gml_lines
graph = parse_graph()
File "/Users/XXXX/.pyenv/versions/3.8.5/lib/python3.8/site-packages/networkx/readwrite/gml.py", line 387, in parse_graph
curr_token, dct = parse_kv(next(tokens))
File "/Users/XXXX/.pyenv/versions/3.8.5/lib/python3.8/site-packages/networkx/readwrite/gml.py", line 315, in tokenize
for line in lines:
File "/Users/XXXX/.pyenv/versions/3.8.5/lib/python3.8/site-packages/networkx/readwrite/gml.py", line 209, in filter_lines
line = line.decode('ascii')
AttributeError: 'int' object has no attribute 'decode'
对应的源代码
import numpy as np
import networkx as nx
gml_path = "XXXX.gml"
gml_path = gml_path.encode("utf-8")
G = nx.read_gml(gml_path)
X = np.array(nx.to_numpy_matrix(G))
print(nx.is_directed(G))
我试过的
我将编码字符代码更改为 ascii 等,但出现错误。
补充信息(固件/工具版本等)
蟒蛇 3.85
网络x 2.1
numpy 1.19.2