Do Cython extension types support class attributes?

后端 未结 3 629
遇见更好的自我
遇见更好的自我 2021-01-11 16:55

Python classes can have class attributes:

class Foo(object):
   bar = 4

Is there an analogous construct for defining class attributes in Cy

3条回答
  •  北海茫月
    2021-01-11 17:21

    You can't do that that way. I don't know whether static attributes are supported, but the "normal" ones have to be accessed from methods, e.g. a constructor:

    cdef class Foo:
        cdef int bar
        def __init__(self):
            self.bar = 4
    

提交回复
热议问题