小编Pwn*_*rus的帖子

Cython扩展类型是否支持类属性?

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)

c python types class cython

10
推荐指数
2
解决办法
4677
查看次数

标签 统计

c ×1

class ×1

cython ×1

python ×1

types ×1