cdef函数下可以引用Python对象吗?
Can Python object be referenced under cdef function?
在下面的代码中,self
是一个 python 对象,因为它是从 def
而不是 cdef
声明的。是否可以在 cdef
函数下引用 python 对象,就像它在下面示例中的 c_function
下的使用方式一样?
我很困惑,因为 cdef
听起来 cdef
是一个 C 函数,所以我不确定它是否能够接受 python 对象。
class A(self, int w):
def __init__():
self.a = w
cdef c_function (self, int b):
return self.a + b
谢谢,
我是OP。
来自“Cython:Python 程序员指南”:
"[...] Nothing prevents us from declaring and using Python objects and dynamic variables in cdef functions, or accepting them as arguments"
所以我把这本书当作对我原来的问题说“是”的书。
在下面的代码中,self
是一个 python 对象,因为它是从 def
而不是 cdef
声明的。是否可以在 cdef
函数下引用 python 对象,就像它在下面示例中的 c_function
下的使用方式一样?
我很困惑,因为 cdef
听起来 cdef
是一个 C 函数,所以我不确定它是否能够接受 python 对象。
class A(self, int w):
def __init__():
self.a = w
cdef c_function (self, int b):
return self.a + b
谢谢,
我是OP。 来自“Cython:Python 程序员指南”:
"[...] Nothing prevents us from declaring and using Python objects and dynamic variables in cdef functions, or accepting them as arguments"
所以我把这本书当作对我原来的问题说“是”的书。