我有以下代码来使用属性映射注释图形:
from graph_tool.all import *
# define graph
g = Graph()
g.set_directed(True)
species = g.new_vertex_property("string")
species_dict = {}
reaction_dict = {}
#add species and reactions
s1 = g.add_vertex()
species[s1] = 'limonene'
species_dict[g.vertex_index[s1]] = 'limonene'
g.vertex_properties["species"] = species
g.vp.species[s1]
当我运行它时,我收到以下错误消息:
File "/home/pmj27/projects/NOC/exergy/make_graph.py", line 45, in <module>
g.vp.species[s1]
AttributeError: 'PropertyDict' object has no attribute 'species'
为什么是这样?如果我g.vp
在我的 IPython 控制台中输入,我会得到{'species': <PropertyMap object with key type 'Vertex' and value type 'string', for Graph 0x7f285d90ea10, at 0x7f285d90ef90>}
答案,所以显然有一个属性映射。