Python类可以具有类属性:
class Foo(object):
bar = 4
Run Code Online (Sandbox Code Playgroud)
是否有类似的结构用于在Cython扩展类型中定义类属性?例如,当我尝试编译以下cython代码时
cdef class Foo:
cdef int bar
bar = 4
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
thing.c:773:3: error: use of undeclared identifier 'bar'
bar = 4;
^
1 error generated.
error: command 'cc' failed with exit status 1
Run Code Online (Sandbox Code Playgroud)