【发布时间】:2020-12-20 21:57:52
【问题描述】:
我正在尝试“cythonize”以下示例代码,其中包括一个 Enum 类的实例:
from enum import Enum
class AnimalType(Enum):
Shark = 0
Fish = 1
class Animal:
def __init__(self, animal_type: AnimalType, weight: float):
self.animal_type = animal_type
self.weight = weight
创建带有类型声明的 .pyx 文件很容易:
cpdef enum AnimalType:
Shark = 0
Fish = 1
cdef class Animal:
cdef double weight
cdef AnimalType animal_type
def __init__(self, animal_type: AnimalType, weight: float):
self.animal_type = animal_type
self.weight = weight
但是,我无法将 .pyx 文件拆分为 .pyx 和 .pxd(标头)文件。您能帮我为我的示例定义一个 .pxd 文件吗?
编辑:我已阅读https://groups.google.com/g/cython-users/c/ZoLsLHwnUY4。这可能是不可能的......
【问题讨论】:
标签: cython header-files