我见过一个使用这种方式定义属性的代码
property sockets:
def __get__(self):
cdef list sockets = []
这和用装饰器声明有什么区别吗?
最佳答案
定义属性函数的 __get__
等方法是遗留语法,已被弃用,取而代之的是 @property
装饰器 - per docs :
There is also a special (deprecated) legacy syntax for defining properties in an extension class:
cdef class Spam:
property cheese:
Cython 生成的代码在功能上是等效的,可以通过检查 C 文件看到,但语法是遗留的、已弃用,并且可能会在未来的 Cython 版本中删除。
关于python - 属性类和属性装饰器有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49155710/