Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make externed enum "public" for Python?

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

like image 596
Niklas R Avatar asked Feb 15 '12 21:02

Niklas R


1 Answers

I have used ctypesgen.py with some success for exporting types and enumerations. This would likely be adequate for both python and cython.

like image 72
Brian Cain Avatar answered Oct 01 '22 22:10

Brian Cain