Providing a Python wrapper to a C++ type.

Christian Gollwitzer auriocus at gmx.de
Tue Oct 16 15:03:13 EDT 2012


Am 16.10.12 18:42, schrieb Evan Driscoll:
> For instance, I used it to wrap the OS's opendir/readdir
> (FindFirstFile/FindNextFile) functions: I just wrote a bit of code using
> Cython's extensions, and I get a module I can import and use as normal.

Well, but for an existing library in C++ possibly SWIG will be the 
easiest way to go; since you already have a header file, it might be 
enough to do

swig -python -c++ myheader.hpp

to get the wrappers generated. This works well in simple cases. For 
complicated cases like trying to wrap large template libraries like STL 
or Boost, it is also necessary to twiddle with SWIGs interface language. 
In many cases, however, this can be #ifdef'ed in the header file itself, 
therefore it is easy to keep the interface in sync with the class library.

	Christian



More information about the Python-list mailing list