2010-03-14 40 views
2

是他们的任何方式来使这个工作,而不牺牲在cdef调用者的cdef? (不使用cpdef)在cdef类中调用cdef

from array import * 
from numpy import * 
cdef class Agents: 
    cdef public caller(self): 
     print "caller" 
     A[1].called() 

    cdef called(self): 
     print "called" 


A = [Agents() for i in range(2)] 

def main(): 
    A[0].caller() 

回答

3

对于Cython A [1]将是一个python对象。如果你希望能够仍然使用CDEF,使用自动投在你的来电者:

cdef public caller(self): 
    cdef Agents agent 
    print "caller" 
    agent = A[1] 
    agent.called() 

您可以在用Cython的-a模式检查知道,如果你正在使用Python或C语言为每个行的代码。 (cython -a yourfile.pyx - >会生成一个yourfile.html,你可以浏览& check)。

相关问题