使外部枚举“公开”对于Python?
我正在包装一个大量使用枚举的库,因此包含许多常量标识符。有没有办法让它们可供 Cython 使用(将它们声明为 extern),同时让它们可供 Python 使用?
我搜索类似这样的内容
cdef extern from *:
public enum:
spam
foo
ham
,它应该替换
cdef extern from *:
enum:
cspam "spam"
cfoo "foo"
cham "ham"
spam = cspam
foo = cfoo
ham = cham
注意:我知道将外部声明移动到 .pxd 文件以避免命名冲突的选项。
谢谢,Niklas
I'm wrapping a library that makes massive use of enumerations and therefore contains many constant identifiers. Is there a way to make them available to Cython (declare them as extern
) and at the same time make them available to Python?
I search for something like this
cdef extern from *:
public enum:
spam
foo
ham
which should replace
cdef extern from *:
enum:
cspam "spam"
cfoo "foo"
cham "ham"
spam = cspam
foo = cfoo
ham = cham
Note: I know about the option to move the extern-declarations to a .pxd file to avoid naming-collision.
Thanks, Niklas
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我使用
ctypesgen.py
在导出类型和枚举方面取得了一些成功。这对于 python 和 cython 来说可能就足够了。I have used
ctypesgen.py
with some success for exporting types and enumerations. This would likely be adequate for both python and cython.