gpt4 book ai didi

inheritance - cython继承

转载 作者:行者123 更新时间:2023-12-04 18:13:47 26 4
gpt4 key购买 nike

我有一个A.pxd(仅包含函数声明)和A.pyx,其中仅包含具有所有函数体的类A。

我比B继承自A,

对于B我有一些功能的B.pxd

蜡梅

class Bclass(A):
#all the funcions body

我现在想如何告诉B.pyx将A识别为类型名称?

我要做的是:

蜡梅
cimport A
import A
from A import Aclass
cdef Bclass(Aclass):
#body

但它告诉我:A不是类型名称

如果我仅在一个file.pyx中执行此操作,则不会出现问题,但与files.pxd一起运行则不会成功。

最佳答案



from A cimport Aclass
cdef class Bclass(Aclass):
# ...

或者

cimport A
cdef class Bclass(A.Aclass):
# ...

请注意, Aclass必须是馈给 cdef的类,Cython extension types不能从Python类继承。

关于inheritance - cython继承,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7651613/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com