/** \ingroup python_interface_vertex
 * \brief Returns a dict with attribue names and values
 */
PyObject* igraphmodule_Vertex_attributes(igraphmodule_VertexObject* self) {
    igraphmodule_GraphObject *o = self->gref;
    PyObject *names, *dict;
    long i, n;

    dict=PyDict_New();
    if (!dict) return NULL;

    names=igraphmodule_Graph_vertex_attributes(o);
    if (!names) {
        Py_DECREF(dict);
        return NULL;
    }

    n=PyList_Size(names);
    for (i=0; i<n; i++) {
        PyObject *name = PyList_GetItem(names, i);
        if (name) {
            PyObject *dictit;
            dictit = PyDict_GetItem(((PyObject**)o->g.attr)[ATTRHASH_IDX_VERTEX], name);
            if (dictit) {
                PyObject *value = PyList_GetItem(dictit, self->idx);
                if (value) {
                    /* No need to Py_INCREF, PyDict_SetItem will do that */
                    PyDict_SetItem(dict, name, value);
                }
            }
        }
    }

    return dict;
}
示例#2
0
/** \ingroup python_interface_vertexseq
 * \brief Returns the list of attribute names
 */
PyObject* igraphmodule_VertexSeq_attribute_names(igraphmodule_VertexSeqObject* self) {
  return igraphmodule_Graph_vertex_attributes(self->gref);
}
/** \ingroup python_interface_vertex
 * \brief Returns the list of attribute names
 */
PyObject* igraphmodule_Vertex_attribute_names(igraphmodule_VertexObject* self) {
    if (!self->gref) return NULL;
    return igraphmodule_Graph_vertex_attributes(self->gref);
}