1

当我写入 pajek 文件然后使用 Networkx 库 python 读回相同的文件时收到错误

   >>> G=nx.read_pajek("eatRS.net")

   >>> nx.write_pajek(G,"temp.net")

   >>> G1=nx.read_pajek("temp.net")

Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "<string>", line 2, in read_pajek
 File "/usr/local/lib/python2.7/dist-packages/networkx/utils/decorators.py", line 193, in _open_file
   result = func(*new_args, **kwargs)
 File "/usr/local/lib/python2.7/dist-packages/networkx/readwrite/pajek.py", line 132, in read_pajek
   return parse_pajek(lines)
 File "/usr/local/lib/python2.7/dist-packages/networkx/readwrite/pajek.py", line 168, in parse_pajek
splitline=shlex.split(str(next(lines)))
 File "/usr/lib/python2.7/shlex.py", line 279, in split
  return list(lex)
 File "/usr/lib/python2.7/shlex.py", line 269, in next
token = self.get_token()
 File "/usr/lib/python2.7/shlex.py", line 96, in get_token
  raw = self.read_token()
 File "/usr/lib/python2.7/shlex.py", line 172, in read_token
r aise ValueError, "No closing quotation"
 ValueError: No closing quotation
4

1 回答 1

0

在networkx中创建一个图形,以pajek格式编写然后再返回对我来说很好。例如gnm_random_graph

import matplotlib.pyplot as np
n = 10
m = 20

G = nx.gnm_random_graph(n,m)
nx.write_pajek(G, "temp.net")
G1 = nx.read_pajek("temp.net")

仅当我将中间图编辑为具有,例如,

"vertex one 0.3456 0.1234 box ic White fos 20

我得到你的ValueError: No closing quotation错误吗?节点标签可以是数字或字符串,但如果它们包含空格,则必须引用名称。来自 Pajek手册

label - 如果标签以字符 A..Z 或 0..9 开头,第一个空格确定标签的结尾(例如:vertex1),包含更多单词的标签必须包含在一对特殊字符中(例如:“vertex 1”)


因此,我建议您检查您的输入文件“eatRS.net”。字符编码、引号不匹配(例如,以 开头"和以 结尾')或节点标签内的换行符可能存在问题?

于 2013-09-09T15:57:24.943 回答