2010-03-14 45 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)。

相關問題