Wrapping C-enum in a Python module with Swig -
i have simple enum in c in myenum.h:
enum myenum { one, two, 3 };
the problem when map python, can access enum through module name, not through myenum. values one, two, 3 included other functions define, instead of being contained myenum.
my api.i file is:
%module api %{ #include "myenum.h" %} %include "myenum.h"
i generate swig
swig -builtin -python api.i
and import python
import _api
and have use enum values _api module:
_api.one _api.two _api.three
while want use them like
_api.myenum.one _api.myenum.two _api.myenum.three
does know how can accomplish this?
there swig feature nspace want want, unfortunately isn't supported python yet. i've had define enum in struct show in manner desire in swig. example:
%module tmp %inline %{ struct myenum { enum { a,b,c }; }; %}
result:
>>> import tmp >>> tmp.myenum.a 0 >>> tmp.myenum.b 1 >>> tmp.myenum.c 2
Comments
Post a Comment