Read C++ enum in python

MRAB python at
Wed Aug 19 01:50:05 CEST 2009

Ludo wrote:
> Hello,
> I work in a very large project where we have C++ packages and pieces of 
> python code.
> I've been googleing for days but what I find seems really too 
> complicated for what I want to do.
> My business is, in python, to read enum definitions provided by the 
> header file of an c++ package.
> Of course I could open the .h file, read the enum and transcode it by 
> hand into a .py file but the package is regularly updated and thus is 
> the enum.
> My question is then simple : do we have :
>     - either a simple way in python to read the .h file, retrieve the 
> c++ enum and provide an access to it in my python script
>     - either a simple tool (in a long-term it would be automatically run 
> when the c++ package is compiled) generating from the .h file a .py file 
> containing the python definition of the enums ?
> Thank you for any suggestion.

Speaking personally, I'd parse the .h file using a regular expression
(re module) and generate a .py file. Compilers typically have a way of
letting you run external scripts (eg batch files in Windows or, in this
case, a Python script) when an application is compiled.

More information about the Python-list mailing list