相关疑难解决方法(0)

在cdef类中混合使用cdef和常规python属性

我正在学习Cython,现在正在尝试它.我尝试了基本的cdef类示例程序,它完美地运行.

现在我要做的是在cdef类类型中混合使用cdef和非cdef混合属性,就像这样

cdef class Context:
    cdef public int byteIndex, bitIndex

    def __init__(self, msg = "", msg_len = 0):
        self.msg = msg 
        self.msg_len = msg_len 
        self.byteIndex = 0
        self.bitIndex = 7
Run Code Online (Sandbox Code Playgroud)

但是一旦我实例化对象我就会收到错误

!! AttributeError: 'c_asnbase.Context' object has no attribute 'msg'

这是否意味着一旦你用cdef定义一个python类,所有自我.*属性必须是cdef定义的?

python cython

7
推荐指数
2
解决办法
1402
查看次数

标签 统计

cython ×1

python ×1