calling a cdef in a cdef class
is their any way to make this work, without sacrificing the cdef in cdef caller? (no use of cpdef either)
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()
For Cython A[1] will be a python object. If you want to be able to still use cdef, use automatic cast in your caller :
cdef public caller(self):
cdef Agents agent
print "caller"
agent = A[1]
agent.called()
You can check with the -a mode in cython to know if you are using Python or C for each lines code. (cython -a yourfile.pyx -> will generate a yourfile.html that you can browse & check).
精彩评论