在下面的代码中,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: A Guide for Python Programmers":
来源: https://books.google.com.hk/books?id=H3JmBgAAQBAJ&pg=PA49&lpg=PA49&dq=python+object+cdef+function&source=bl&ots=QI9If_wiyR&sig=ACfU3U1CmEPBaEVmW0UN1_9m9G8B9a6oFQ&hl=en&sa=X&ved=2ahUKEwiBgs3Lw5vqAhXSZt4KHTs0DK0Q6AEwBHoECAoQAQ#v=onepage&q=python%20object%20cdef%20function&f=false
"[...] Nothing prevents us from declaring and using Python objects and dynamic variables in cdef functions, or accepting them as arguments"
因此,我将此视为对我最初的问题说"是"的书。