在Cython代码中定义将在cod的C部分中使用的枚举

2024-10-02 00:21:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我在cython头文件api.pxd中定义了和enum

ctypedef enum InstructionType:
    default = 0
    end_if = 1
    end_loop = 2
    backward_jump_here = 4

我还检查了将ctypedef转换为cdef是否有效(但它没有)。在

我想在某个类的__cinit__方法中使用此枚举中的值:

^{pr2}$

我得到了编译错误:

    self.type = InstructionType.end_if
                              ^
------------------------------------------------------------
 /home/(...)/instructions.pyx:149:35: 'InstructionType' is not a constant, 

有没有办法以这种方式定义和使用enum?在


Tags: loopapidefaultifhere定义头文件enum

热门问题