【发布时间】:2015-08-01 21:06:22
【问题描述】:
我正在使用 Cython 来包装 C 库。 C 库的头文件定义了许多常量,所以在我的 cython 模块中,我有类似的内容:
cdef extern from "lib.h":
cdef int CONST_A = 0
cdef int CONST_B = 1
当我编译扩展时,常量在 Python 中不可用。我尝试做这样的事情,但它似乎不起作用:
cdef extern from "lib.h":
cdef int CONST_A = 0
cdef int CONST_B = 1
CONST_A = CONST_A
CONST_B = CONST_B
关于如何使这些常量在 Python 中可用的任何想法?
【问题讨论】:
-
我认为您可以使用
cpdef而不是cdef作为常量。 -
我试过了,还是不行。