Python 在Cython中创建对象列表

Python 在Cython中创建对象列表,python,list,object,cython,Python,List,Object,Cython,我想知道如何在Cython中创建C对象列表 下面是一个简单的工作示例: 西姆波特赛顿酒店 b = real_test() print(b) cdef real_test(): cdef int a cdef Node b = Node() a = b.h return a cdef class Node: cdef int h def __cinit__(self): self.h = 3 但不是这个: cimport cyt

我想知道如何在Cython中创建C对象列表

下面是一个简单的工作示例:

西姆波特赛顿酒店

b = real_test()
print(b)

cdef real_test():
    cdef int a
    cdef Node b = Node()
    a = b.h
    return a

cdef class Node:
    cdef int h
    def __cinit__(self):
        self.h = 3
但不是这个:

cimport cython

b = real_test()
print(b)

cdef real_test():
    cdef int a
    cdef Node *b = [Node(),Node(),Node()]
    a = b[0].h
    return a

cdef class Node:
    cdef int h
    def __cinit__(self):
        self.h = 3
如何做到这一点


谢谢

我不确定这是否正确,但这是有效的:

cimport cython

b = real_test()
print(b)

cdef real_test():
    cdef int a
    cdef list b = [Node(),Node(),Node()]
    a = b[0].h
    return a

cdef class Node:
    cdef int h
    def __cinit__(self):
        self.h = 3
    property h:
        def __get__(self):
          return self.h
        def __set__(self, float value):
          self.h = value