cython继承 [英] cython inheritance
问题描述
我有一个A.pxd(仅带有函数声明)和A.pyx,其中仅包含具有所有函数主体的类A。
I have a A.pxd (with just declaration of functions) and A.pyx that contains just a class A with all the function body.
比起我有从A继承来的B,
Than I have B that inherits from A,
对于BI,B.pxd具有某些功能
and for B I have B.pxd with some functions
B.pyx
class Bclass(A):
#all the funcions body
我现在想告诉B.pyx将A认为类型名称?
I want to now how to tell to B.pyx to ricognise A as a type name?
我要做什么:
B.pyx
cimport A
import A
from A import Aclass
cdef Bclass(Aclass):
#body
但它说我:A不是类型名称
but it says me: A is not a type name
如果我仅在一个file.pyx中执行此操作,它就不会出现问题,但是与files.pxd一起运行却不会成功。
If i do this in just one file.pyx it works without problems but working with files.pxd it does not go.
推荐答案
使用
from A cimport Aclass
cdef class Bclass(Aclass):
# ...
或
cimport A
cdef class Bclass(A.Aclass):
# ...
请注意 Aclass
必须是 cdef
的进餐类,Cython 扩展类型 不能继承自Python类。
Note that Aclass
must be cdef
'fed class, Cython extension types cannot inherit from Python classes.
这篇关于cython继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!